Info
此问题已关闭。 请重新打开它进行编辑或回答。
plot values in the loop
1 次查看(过去 30 天)
显示 更早的评论
Hello
my code is something like this
p=3
for k=1:p
%something
if %something
d=d+1
elseif %something
d=d-2
end
plot(k,d,'o')
hold on
end
I get three values of d corresponding to three values of k. I want to plot these values so that the x axies will be the values of k and the y axis will be the values of d
The thing is, with this code I get only points, but I want to link them with lines. How can I do that?
Thank you
3 个评论
Mehmed Saad
2020-4-3
the easiest way is to store your variables in a vector with each iteration and plot them at the end of for loop, in this way they will be joined together
回答(2 个)
KSSV
2020-4-3
p=3 ;
k = 1:p ;
val = zeros(1,p) ;
for i = 1:length(p)
%something
if %something
d=d+1
val(i) = d ;
elseif %something
d=d-2
val(i) = d ;
end
end
plot(k,val,'-o')
4 个评论
此问题已关闭。
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!