Save all figures using figure title error
조회 수: 12 (최근 30일)
이전 댓글 표시
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
채택된 답변
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'
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Labels and Annotations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!