saving figure with title as name of file

20 ビュー (過去 30 日間)
C.G.
C.G. 2021 年 10 月 29 日
コメント済み: C.G. 2021 年 10 月 29 日
I have 4 .mat files. I extract the data from these, plot them and save each figure.
Now, I want the title of the plot, and the name of the png file i save to be the name of the .mat file the data is from.
How do I go about doing this?
files = dir('*.mat');
num_files = length(files);
resGT = zeros(100000,num_files);
%calculate resGT
for a = 1:num_files
load(files(a).name)
v = vel(1:100000,:);
e = num;
timestep = height(vel);
time_sec = timestep/100;
inputrate = 1;
resGT(:,a) = sqrt(v(:,1).^2 +v(:,2).^2 + v(:,3).^2);
end
%plot
for a = 1:num_files
figure()
cla;
plot(resGT(:,a)) %GT over time
title ('GT through time')
xlabel('Time')
ylabel('GT')
saveas(gcf,sprintf('ResGT%d.png',a))
hold on
pause(0.5)
end

採用された回答

Geoff Hayes
Geoff Hayes 2021 年 10 月 29 日
編集済み: Geoff Hayes 2021 年 10 月 29 日
@C.G. - since you have the file name in your files structure, then you could just do
for a = 1:num_files
matFileName = files(a).name;
figure()
cla;
plot(resGT(:,a)) %GT over time
title (matFileName)
xlabel('Time')
ylabel('GT')
saveas(gcf,sprintf('%s.png',matFileName))
hold on
pause(0.5)
end
  1 件のコメント
C.G.
C.G. 2021 年 10 月 29 日
thats great thank you!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSpecifying Target for Graphics Output についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by