Yijapod
Yijapod

Reputation: 1

Can automatically enumerate figures or keep tokens in matlab?

In a live script in matlab, I plot multiple figures, and I use this code to enumerate the figures:

FigureQuantity=1
plot(data_1)
title('Figure '+string(FigureQuantity))

Then on another code section I do it again

FigureQuantity=FigureQuantity+1
plot(data_n)
title('Figure '+string(FigureQuantity))

The problem is that if I run the last code section again, FigureQuantity gets updated and the enumeration of figures gets broken.

There is any way to get the number of tokens ordered by his code appearance on the live script? (independent of how many times the section code is run)

I would like to keep tokens so I can mix inserted images and plots. And I want to export the document as PDF (not to show plots in an application or an independent window). What I need is something like MS Word enumeration of figures and tables.

I found this Matlab documentation: Number Section Headings, Table Titles, and Figure Captions Programmatically, but it appears to be used for creation of MS Word or HTML documents, and not to enumerate images on Matlab live scripts.

I do not understand how to use it, or if that is his purpose on Matlab.

Upvotes: 0

Views: 165

Answers (1)

Ori Yarden PhD
Ori Yarden PhD

Reputation: 1455

I'm assuming you're updating the data_n variable live as well; otherwise, if you're defining these variables manually then not doing so for the figure variables isn't really the solution I think you're looking for.

Why not for-loop through the figure updates?

for FigureQuantity = 1:numberOfFigureQuantities
    figure(FigureQuantity);
    hold on;
    plot(data_n(FigureQuantity))
    title(strcat('Figure Number: ',num2str(FigureQuantity)));
end

The figure count corresponding to the FigureQuantity will index the appropriate figure and will update that figure if it already existed. This is the solution I think you're looking for; if not, please clarify.

Upvotes: 0

Related Questions