How to apply LOOP Function to this simple problem??

1 次查看(过去 30 天)
....
....
...
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.

采纳的回答

Image Analyst
Image Analyst 2013-3-24
编辑:Image Analyst 2013-3-24
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.

更多回答(1 个)

Walter Roberson
Walter Roberson 2013-3-24

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by