Save all figures using figure title error

14 vues (au cours des 30 derniers jours)
EB
EB le 2 Mar 2022
Commenté : EB le 2 Mar 2022
Hello,
I have been using the following code (which I found previously on the site but can't find the author, apologies!) to save all my open figures as a MATLAB figures. The MATLAB figure files are named using each figure's title. I am using version 2021b.
FolderName = pathname; % Folder to save figures
FigList = findobj(allchild(0), 'flat', 'Type', 'figure');
for iFig = 1:length(FigList)
FigHandle = FigList(iFig);
ax = findobj(FigHandle, 'type', 'axes');
FigName = ax.Title.String;
set(0, 'CurrentFigure', FigHandle);
savefig(FigHandle, fullfile(FolderName, [FigName '.fig']));
end
I have been using this code for weeks without issue and have encountered this error only recently with the above underlined line FigName = ax.Title.String
ERROR: Intermediate dot '.' indexing produced a comma-separated list with 3 values, but it must produce a single value when followed by subsequent indexing operations.
I need to be able to access the figure's Title, which is a string. If anyone knows how to circumvent this error or another code to access the figure's title, I would greatly appreciate it.
Thank you!

Réponse acceptée

Benjamin Thompson
Benjamin Thompson le 2 Mar 2022
The figure handle has some properties that may be useful, including Name, Number, and NumberTitle.
figure, plot(1:10,2:2:20);
fig = gcf
>> fig.Name = "Hello World"
fig =
Figure (1: Hello World) with properties:
Number: 1
Name: 'Hello World'
Color: [0.940000000000000 0.940000000000000 0.940000000000000]
Position: [488 342 560 420]
Units: 'pixels'
Show all properties
>> fig.Name
ans =
'Hello World'

Plus de réponses (0)

Catégories

En savoir plus sur Labels and Annotations dans Help Center et File Exchange

Produits


Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by