plot values in the loop
Info
Diese Frage ist geschlossen. Öffnen Sie sie erneut, um sie zu bearbeiten oder zu beantworten.
Ältere Kommentare anzeigen
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 Kommentare
KSSV
am 3 Apr. 2020
whats is that something?
Mehmed Saad
am 3 Apr. 2020
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
Ani Asoyan
am 3 Apr. 2020
Antworten (2)
Jakob B. Nielsen
am 3 Apr. 2020
do
plot(k,d,'o-')
instead, that will give you o's connected by lines.
KSSV
am 3 Apr. 2020
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 Kommentare
Mehmed Saad
am 3 Apr. 2020
p=3 ;
k = 1:p ;
val = zeros(1,p);
for i = 1:p % here either p or length(k)
%something
if %something
d=d+1
val(i) = d ;
elseif %something
d=d-2
val(i) = d ;
end
end
plot(k,val,'-o')
Ani Asoyan
am 3 Apr. 2020
Ani Asoyan
am 3 Apr. 2020
Diese Frage ist geschlossen.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!