Save all figures using figure title error
16 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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!
0 Kommentare
Akzeptierte Antwort
Benjamin Thompson
am 2 Mär. 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'
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Labels and Annotations finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!