Save all figures using figure title error

14 ビュー (過去 30 日間)
EB
EB 2022 年 3 月 2 日
コメント済み: EB 2022 年 3 月 2 日
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!

採用された回答

Benjamin Thompson
Benjamin Thompson 2022 年 3 月 2 日
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'
  1 件のコメント
EB
EB 2022 年 3 月 2 日
Thank you!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLabels and Annotations についてさらに検索

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by