At the beginning of preparation for this post, I asked Lars Schatkowski, the co-author today, to summarize the benefits of the MATLAB Live Editor in a single phrase. He seemed to be expecting this one and replied: “Christoph, it is actually a new way of coding, because it includes the output of an algorithm to the script itself!” So, no matter how you are using MATLAB today, we think familiarizing yourself with the MATLAB Live Editor is beneficial.
By the way, all the credit for preparing the content goes to Lars. Thanks very much!
MATLAB code and report in a single document
Script isn’t just ASCI text anymore but an interactive document that combines MATLAB code, inline output, formatted text, equations, and images in a single environment.
Writing MATLAB code and documenting the outcome at the same time is a great time-saver. I have experienced that project teams with high fluctuation (fancy description for automotive student teams, isn’t it?) have to be good at documenting their know-how or they will become less competitive over time. I imagine that quasi-automated report generation can be a strong asset for longterm success.
Among the many features, the Live Editor for example allows to:
- Format code and comments like you would do with a word processor
- Obtain compact output next to the code that produces it
- Intuitively manipulate plots
- Write equation using LaTeX or an equation editor
[Click and magnify the images to explore how live editor may look like.]
Jumpstart into analytical equation solving
Live editor is also a powerful user interface to work with equations. They look exactly the same as you would write them with pen on paper. That simplifies finding typos compared to equations represented by ASCI text a lot. Think about your calculus exam and imagine MATLAB differentiating and re-arranging equations for you. Symbolic Math Toolbox™ is now tied a lot closer to your MATLAB user interface.
Convert all your code to live scripts?
Should you now convert all scripts to live scripts? You certainly could, but that’s probably not the most practical solution. At first, for code that requires a fair part of documentation, it is beneficial to use live scripts! Just think about ramping-up new team members and resulting time savings. Secondly, think about reports that you are going to create. That tasks drops from your plate completely with live scripts. On the other hand, scripts or functions that are well-defined for a certain purpose may remain as they are and can easily be called from live scripts.
How about debugging? No worries! You still can work with >>dbstop, >>dbstep and Co. Currently, the visual toolbar alternatives such as setting breakpoints, step in or out are not support but you can ‘enable’ that by saving the live scripts as scripts.
A new and noteworthy alternative is what I call “visual debugging”. This is an extremely intuitive method of understanding how the code works. Removing certain semicolons reveals the output right next to your code and you can see how errors evolve compared to only seeing the error message after the script has failed.
Let me again try to summarize in a single phrase: Nothing is turned to the negative and you can benefit a lot.
Find here some links to related resources:
- Examples in the documentation
- Release notes with new features being added
- R2016b: Pan, zoom, and rotate axes in output figures. Create and edit equations interactively using the equation editor. Create new sections and format text quickly using auto formatting. Automatically rename all functions or variables in a live script. Drag and drop selected code and text within a live script and between other applications. View outputs sooner when running live scripts
- R2017a: Edit a figure interactively including title, labels, legend, and other annotations. Get suggestions for mistyped commands and variables. Copy live script outputs to other applications. Hover over variables to see their current value
- Live Editor in the browser
Feel invited to start and join a discussion. I am curious to learn whether things are applicable to your work and what else you would need.