How to add captions to figures in a LiveScript that also include figure numbers

35 ビュー (過去 30 日間)
Cory Dinkle
Cory Dinkle 2022 年 1 月 20 日
コメント済み: Cory Dinkle 2022 年 1 月 21 日
Hello, I am using Live Editor to create a professional report that can be automatically generated with data. I am attempting to add captions to the figures, and have been unsuccessful at:
  • Center-justifying the caption
  • Reducing the caption font size
As an example, I have inserted a figure manually, and directly below that I have this code:
figureSpec = "Figure %d: Results vs. Time";
figureNumber = figureNumber+1;
"figureNumber" has been established at the beginning of the LiveScript.
The overall objective here is to have figure numbers that will auto-update if I happen to remove a prior figure, or include extra figures. It doesn't seem to be an option to add figure numbers to captions, or even captions to figures for that matter. Any suggestions would be great, thanks!
  2 件のコメント
Cory Dinkle
Cory Dinkle 2022 年 1 月 21 日
Thanks, these figures are already created, and in some cases they are not Matlab figures but simple schematics, therefore the first option would not work unfortunately. The second and third suggestions may do what I need, though I think I may be spending too much time trying to automate such a simple function (figure numbering).
Finally, yes the report generator would definitely do this, but I don't think I am going to put in a request to HR for a $1k add-on that is much less capable than simply writing in LaTeX and importing the figures and data that way. Thank you for the suggestions!


回答 (1 件)

Ankit 2022 年 1 月 21 日
編集済み: Ankit 2022 年 1 月 21 日
@Cory Dinkle.. I would recommend if you can use annotations. With annotations it is easy to change different properties like alignment, font size, name etc very easily. I hope this could help you to generate your report as expected.
close all;
data = [2 4 6 7 8 7 5 2];
function captionFigure()
figList = sort(get(0,'Children'));
i = length(figList);
figureSpec = {['Figure: ' num2str(i) ' Results vs. Time']};
dim = [0.1, 1.0, 0.8, 0.0];
a = annotation('textbox', dim, 'String', figureSpec, 'FitBoxToText', 'on', 'LineStyle', 'none');
a.Color = 'red';
a.FontSize = 12;
a.HorizontalAlignment = 'center';


Find more on Printing and Saving in Help Center and File Exchange




Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by