Update Code with Figure Changes
When modifying output figures in live scripts, changes to the figure are not automatically added to
the script. With each interaction, MATLAB generates the code needed to reproduce the interactions
and displays this code either underneath or to the right of the figure. Use the Update Code button to
add the generated code to your script. This ensures that the interactions are reproduced the next
time you run the live script.
For example, in the live script patients.mlx, after zooming in on patients with a height of 64, click
the Update Code button. MATLAB adds the generated code after the line containing the code for
creating the plot.
xlim([61.31 69.31])
ylim([116.7 183.3])
If MATLAB is unable to determine where to place the generated code, the Update Code button is
disabled. This occurs, for example, if you modify the code without running the script again. In this
case, use the Copy button to copy the generated code into the clipboard. You then can paste the code
into your script at the appropriate location.
Add Formatting and Annotations
In addition to exploring the data, you can format and annotate your figures interactively by adding
titles, labels, legends, grid lines, arrows, and lines. To add an item, first select the desired figure.
Then, go to the Figure tab and, in the Annotations section, select one of the available options. Use
the down arrow on the right side of the section to display all available annotations. To add a
formatting or annotation option to your favorites, click the star at the top right of the desired
annotation button. To undo or redo a formatting or annotation action, click
or
at the upper
right corner of the toolstrip.
Annotation options include:
•
Title — Add a title to the axes. To modify an existing title, click the existing title and enter
the modified text.
•
X-Label,
Y-Label — Add a label to the axes. To modify an existing label, click the
existing label and enter the modified text.
•
Legend — Add a legend to the figure. To modify the existing legend descriptions, click the
existing descriptions and enter the modified text. Select Remove Legend from the Annotations
section to remove the legend from the axes.
•
Colorbar — Add a color bar legend to the figure. Select Remove Colorbar from the
Annotations section to remove the color bar legend from the axes.
•
Grid,
X-Grid,
Y-Grid — Add grid lines to the figure. Select Remove Grid from
the Annotations section to remove all the grid lines from the axes.
•
Line,
Arrow,
Text Arrow,
Double Arrow — Add a line or arrow
annotation to the figure. Draw the arrow from tail to head. To move an existing annotation, click
19 Live Scripts and Functions
19-14
When modifying output figures in live scripts, changes to the figure are not automatically added to
the script. With each interaction, MATLAB generates the code needed to reproduce the interactions
and displays this code either underneath or to the right of the figure. Use the Update Code button to
add the generated code to your script. This ensures that the interactions are reproduced the next
time you run the live script.
For example, in the live script patients.mlx, after zooming in on patients with a height of 64, click
the Update Code button. MATLAB adds the generated code after the line containing the code for
creating the plot.
xlim([61.31 69.31])
ylim([116.7 183.3])
If MATLAB is unable to determine where to place the generated code, the Update Code button is
disabled. This occurs, for example, if you modify the code without running the script again. In this
case, use the Copy button to copy the generated code into the clipboard. You then can paste the code
into your script at the appropriate location.
Add Formatting and Annotations
In addition to exploring the data, you can format and annotate your figures interactively by adding
titles, labels, legends, grid lines, arrows, and lines. To add an item, first select the desired figure.
Then, go to the Figure tab and, in the Annotations section, select one of the available options. Use
the down arrow on the right side of the section to display all available annotations. To add a
formatting or annotation option to your favorites, click the star at the top right of the desired
annotation button. To undo or redo a formatting or annotation action, click
or
at the upper
right corner of the toolstrip.
Annotation options include:
•
Title — Add a title to the axes. To modify an existing title, click the existing title and enter
the modified text.
•
X-Label,
Y-Label — Add a label to the axes. To modify an existing label, click the
existing label and enter the modified text.
•
Legend — Add a legend to the figure. To modify the existing legend descriptions, click the
existing descriptions and enter the modified text. Select Remove Legend from the Annotations
section to remove the legend from the axes.
•
Colorbar — Add a color bar legend to the figure. Select Remove Colorbar from the
Annotations section to remove the color bar legend from the axes.
•
Grid,
X-Grid,
Y-Grid — Add grid lines to the figure. Select Remove Grid from
the Annotations section to remove all the grid lines from the axes.
•
Line,
Arrow,
Text Arrow,
Double Arrow — Add a line or arrow
annotation to the figure. Draw the arrow from tail to head. To move an existing annotation, click
19 Live Scripts and Functions
19-14
