How to loop over multiple data and save the plot?
1 次查看(过去 30 天)
显示 更早的评论
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.
0 个评论
回答(1 个)
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
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!