Why can't I plot such an easy graph?
Ältere Kommentare anzeigen
Dear community,
Why can't I plot such an easy graph?
for i = 1:100
x(1,:) = 1 + 2*i;
y(1,:) = 3 + i;
end
plot(x,y)
I have two arrays, how can I plot this?
Thanks in advance
1 Kommentar
Stephen23
am 18 Dez. 2014
Learn how to vectorize in MATLAB:
Akzeptierte Antwort
Weitere Antworten (1)
Azzi Abdelmalek
am 12 Dez. 2014
for i = 1:100
x(i) = 1 + 2*i;
y(i) = 3 + i;
end
plot(x,y)
2 Kommentare
Moj
am 12 Dez. 2014
Ilham Hardy
am 12 Dez. 2014
x(i) not x(1,:)
You loop nothing when i (your loop index) is not used!
PS: Two reasons of not using "i" as a loop index:
- 1. "i" is actually square-root of -1
- 2. "i" and "1" is quite difficult for human eyes to distinguish!
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!