For loop and adding elements to an array. How to?
Ältere Kommentare anzeigen
I have some function y(x). I would like to generate a list of y values for x between -10^-3 and 10^-3 in 10^-4 intervals and plot y vs x. I'm trying to do something simpler and less messy first for practice:
function test
global x
for n = -5; n < 5; n+1;
x(end+1)=2*n;
end
end
but this leaves me with x = -10. Why? What am I doing wrong and how could I fix it? Also, is there a way to make an array of x AND their corresponding y values simultaneously and then just plot that one thing? Like list = {{1,1},{2,4},{3,6},{4,8}} and plot this as pairs of coordinates.
5 Kommentare
per isakson
am 21 Mai 2015
Re   for n = -5; n < 5; n+1;   see help on for
per isakson
am 21 Mai 2015
"I guess for n=-5:1:5 works"   Did you try it?
Solarmew
am 21 Mai 2015
Walter Roberson
am 21 Mai 2015
Where did you find that help file?
Akzeptierte Antwort
Weitere Antworten (0)
Kategorien
Mehr zu Loops and Conditional Statements finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!