How to loop over multiple data and save the plot?

1 回表示 (過去 30 日間)
Ritesh Chandra Tewari
Ritesh Chandra Tewari 2021 年 7 月 26 日
回答済み: Yongjian Feng 2021 年 7 月 26 日
I am using matlab online. I have 2000 dat files as data. Whenever I run the code, the folder appears and I have to manually select the data file. I want to loop over all the data and automatically save the plot. How to do that.

回答 (1 件)

Yongjian Feng
Yongjian Feng 2021 年 7 月 26 日
Try this:
files = dir("*.mat");
for i=1:length(files)
clf;
file = files(i);
load(file.name);
plot(x, y);
[~, fname, ~] = fileparts(file.name);
outfile = [fname '.png'];
saveas(gcf, outfile);
end

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

タグ

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by