How can I create multiple figures in a loop?
98 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
B C
el 8 de Nov. de 2013
Respondida: Image Analyst
el 8 de Nov. de 2013
I'm trying to plot graphs of the same variables from multiple files. The code below just gives me the same graph five times. How do I get the loop to plot a new figure for each different file?
files=dir('s*.mat');
for i=1:length(files)
load (files(i).name)
end
for i=1:length(files)
figure(i)
plot(data.time,data.s)
hold on
end
0 comentarios
Respuesta aceptada
Image Analyst
el 8 de Nov. de 2013
That's because if all your mat files have variables of the same name in them - data - then they keep overwriting each other and only the last data survives. You'd have to combine the for loops so that you load and then plot at each iteration so you plot the data for the mat file you just loaded.
for k = 1 : length(files)
load (files(k).name)
figure(k)
plot(data.time,data.s)
hold on
end
0 comentarios
Más respuestas (1)
Walter Roberson
el 8 de Nov. de 2013
Each time you are load()'ing a file, you are overwriting the previous "data" variable.
0 comentarios
Ver también
Categorías
Más información sobre Loops and Conditional Statements en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!