How to apply LOOP Function to this simple problem??

1 visualizzazione (ultimi 30 giorni)
....
....
...
figure(1)
plot(t(1:32768),x1,'r','linewidth',1)
title('Waveform','Fontname','Times new roman','FontSize',35,'fontweight','b')
set(gca, 'FontName','Times New Roman', 'FontSize',35,'fontweight','b')
xlabel('Time (s)','Fontname','Times new roman','FontSize',35,'fontweight','b')
ylabel('Ampiltude (mils)','Fontname','Times new roman','FontSize',35,'fontweight','b')
I would like to generate multiple graphs indvidually (say 10) between t and x1,x2,x3,x4.....x10 such that when i run the command, 10 separate graph files open at once with name such as figure1, figure2, figure3,.....figure10. Kindly tell me how to apply loop function here.

Risposta accettata

Image Analyst
Image Analyst il 24 Mar 2013
Modificato: Image Analyst il 24 Mar 2013
Assuming you have a known, fixed number of xn variables, and it doesn't change with each run of the program, you can just simply wrap it in a loop:
for k = 1 : 10
if k == 1
x = x1;
elseif k == 2
x = x2;
elseif k == 3
x = x3;
elseif k == 4
x = x4;
elseif k == 5
x = x5;
elseif k == 6
x = x6;
elseif k == 7
x = x7;
elseif k == 8
x = x8;
elseif k == 9
x = x9;
elseif k == 10
x = x10;
end
figure;
plot(t(1:32768),x,'r','linewidth',1)
title('Waveform','Fontname','Times new roman','FontSize',35,'fontweight','b')
set(gca, 'FontName','Times New Roman', 'FontSize',35,'fontweight','b')
xlabel('Time (s)','Fontname','Times new roman','FontSize',35,'fontweight','b')
ylabel('Ampiltude (mils)','Fontname','Times new roman','FontSize',35,'fontweight','b')
end
If you don't have 10 x variables with each run, then you must be doing what the FAQ explicitly recommends that you don't do.

Più risposte (1)

Walter Roberson
Walter Roberson il 24 Mar 2013

Categorie

Scopri di più su Line Plots in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by