What's the correct syntax if you want to name the files dynamically when using exportgraphics?
I have a cell array A with 16 titles in each columns that are assigned to the colorbar string. I want to use the same titles to name the files.
for k = 1:16
%rest of the code
c = colorbar;
c.Label.String = string (A (:,k));
exportgraphics(gcf, string (A(:,k)) '.png' ,'Resolution',DPI) %this doesn't work
end

 採用された回答

Ive J
Ive J 2022 年 3 月 22 日

1 投票

% A = {'name1', ...}
for k = 1:16
%rest of the code
c = colorbar;
c.Label.String = A{k};
exportgraphics(gcf, string(A{k}) + ".png" ,'Resolution',DPI) %this doesn't work
end
You could also use strcat, join or similar functions.

10 件のコメント

Pelajar UM
Pelajar UM 2022 年 3 月 22 日
編集済み: Pelajar UM 2022 年 3 月 22 日
Perfect! Is there a way to avoid uifigure from popping out every time you try to export the plot? I close it at the end of the loop but it would be good if it doesn't show up in the first place.
Ive J
Ive J 2022 年 3 月 22 日
You can set visible property of figure to off when creating one, and close if afterwards:
for
fig = figure('Visible', 'off');
ax = axes(fig);
plot(ax, 1:10); % plot something
exportgraphics(fig, 'test.png')
close(fig)
end
Pelajar UM
Pelajar UM 2022 年 3 月 22 日
Wonderful. Thank you so much. On a related note, what if I want to output the same loop to some UIAxes:
s = trisurf(F,P(:,1),P(:,2),P(:,3),app.UITable4.Data(:,k+5),'Parent', app.UIAxes40_k);
app.UIAxes40_k and app.UIAxes40_(k) don't work.
Ive J
Ive J 2022 年 3 月 22 日
Not sure about that (not experienced with apps), but this works:
ax = uiaxes;
[x,y] = meshgrid(1:15,1:15);
z = peaks(15);
T = delaunay(x,y);
trisurf(T,x,y,z, 'parent', ax)
Pelajar UM
Pelajar UM 2022 年 3 月 22 日
Yes, it works without the "k". I mean how do you incorporate k (k represents the loop) in the title of the UIAxes?
for k = 1:11
s = trisurf(F,P(:,1),P(:,2),P(:,3),app.UITable4.Data(:,k+5),'Parent', app.UIAxes40_k);
set(s,'LineWidth',0.1);
s.EdgeColor = 'none';
colormap jet;
c = colorbar;
c.Label.String = A{k};
end
Ive J
Ive J 2022 年 3 月 22 日
Do you have multiple axes or only one axis that you like to update it within the loop? In case of one axis, you don't need to pass the k counter within the loop (it's just one single axis: app.UIAxes).
Pelajar UM
Pelajar UM 2022 年 3 月 22 日
I have multiple axes. Basically the plots that I am exporting, I want to show them all next to each other (11 separate axes with names app.UIAxes40_1, app.UIAxes40_2, and so on....
Ive J
Ive J 2022 年 3 月 22 日
So you need to pass the corresponding axis tag to trisurf:
for ...
s = trisurf(..., 'Parent', app.("UIAxes40_" + k);
end
Pelajar UM
Pelajar UM 2022 年 3 月 22 日
Exactly what I was looking for. Thanks a lot!
Ive J
Ive J 2022 年 3 月 22 日
Glad it works
cheers!

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeCreating, Deleting, and Querying Graphics Objects についてさらに検索

タグ

質問済み:

2022 年 3 月 22 日

コメント済み:

2022 年 3 月 22 日

Community Treasure Hunt

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

Start Hunting!

Translated by