how to plot only one iteration in for loop?
4 次查看(过去 30 天)
显示 更早的评论
A=[2 2 2; 3 3 3; 1 1 1];
B=[1 2 3];
As you can see it bellow, this loop consist of 3 iterations. Can i ask Matlab to plot the second case or third case only? if its possible, please tell me how?
for i = 1:3
C = B + A(1:end,i)
end
C1 =
3
5
4
C2 =3
5
4
C3 =3
5
4
plot (x,C2)
or
plot (x,C3)
Thank you guys for your help, I appreciate any help from you
2 个评论
回答(4 个)
David Sanchez
2013-5-29
for i = 1:3
C = B + A(1:end,i);
if i==2
disp(C);
end
end
2 个评论
Image Analyst
2013-5-29
编辑:Image Analyst
2013-5-29
That is not a big loop. Now if you get into the tens of millions of iterations, then you're getting big, but 100 is far, far from a "big loop" so don't worry about it. There is an unjust fear of loops going around. For example, look at this loop where I iterate a million times:
tic;
count = 0;
for k = 1 : 1000000
count = count + 1;
end
toc
Now look at the elapsed time:
Elapsed time is 0.0071 seconds.
Muruganandham Subramanian
2013-5-29
编辑:Muruganandham Subramanian
2013-5-29
what is x?..see while plotting the size of xlabel and ylabel should be same.. In ur code x might be
x=[1 2 3];
If its right, then you can do it by
for i = 1:3
C = B + A(1:end,i);
if i~=1
plot(x,C);
end
end
Andrei Bobrov
2013-5-29
id = [4 10 26 78]; % Let id case's use for the plotting.
for i1 = 1:100
C = B + A(1:end,i1);
if ismember(i1,id)
plot(x,C);
end
end
另请参阅
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!