Plot inside a for loop
Afficher commentaires plus anciens
hi all, I need your help. I am trying to plot a graph inside a for loop but only dots is appearing on the plot. the dots are not link with each other here is my code:
how can I make a clear line graph with all the dots joined. Help me please its urgent!!!
1 commentaire
Walter Roberson
le 2 Avr 2012
http://www.mathworks.com/matlabcentral/answers/29922-why-your-question-is-not-urgent-or-an-emergency
Réponse acceptée
Plus de réponses (1)
saima
le 31 Mar 2012
0 votes
because each time loop runs your value of x and y becomes a scaler. try to use other variable than x and try to accumulate the values and then use the plot outside the loop
2 commentaires
saima
le 31 Mar 2012
can help you elaborately if you explain your code in a little detail
Kostas
le 31 Mar 2012
try something like this
k=0; %initialize k
for x = 0:250
.
k=k+1 %raise k value +1 in each iteration
a(k) = x * ....;
b(k) = x * ....;
.
y(k) = a + b; % accumulate all values to the vector y, has the same size like x vector
end
x=x(:);
plot(x,y) %x and y are vectors
Catégories
En savoir plus sur Loops and Conditional Statements dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!