How to loop over multiple data and save the plot?

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.

Respuestas (1)

Yongjian Feng
Yongjian Feng el 26 de Jul. de 2021
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

Categorías

Más información sobre Loops and Conditional Statements en Centro de ayuda y File Exchange.

Productos

Versión

R2021a

Etiquetas

Preguntada:

el 26 de Jul. de 2021

Respondida:

el 26 de Jul. de 2021

Community Treasure Hunt

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

Start Hunting!

Translated by