exportgraphics dynamic file name
現在この質問をフォロー中です
- フォローしているコンテンツ フィードに更新が表示されます。
- コミュニケーション基本設定に応じて電子メールを受け取ることができます。
エラーが発生しました
ページに変更が加えられたため、アクションを完了できません。ページを再度読み込み、更新された状態を確認してください。
古いコメントを表示
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
2022 年 3 月 22 日
% 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
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
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
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
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
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
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
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
2022 年 3 月 22 日
So you need to pass the corresponding axis tag to trisurf:
for ...
s = trisurf(..., 'Parent', app.("UIAxes40_" + k);
end
Pelajar UM
2022 年 3 月 22 日
Exactly what I was looking for. Thanks a lot!
Ive J
2022 年 3 月 22 日
Glad it works
cheers!
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Creating, Deleting, and Querying Graphics Objects についてさらに検索
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の MathWorks のサイトは、お客様の地域からのアクセスが最適化されていません。
南北アメリカ
- América Latina (Español)
- Canada (English)
- United States (English)
ヨーロッパ
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
