Why can't I plot such an easy graph?
1 次查看(过去 30 天)
显示 更早的评论
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
采纳的回答
Jacob
2014-12-12
Use
v = 1:100;
x(1,:) = 1+2.*v;
y(1,:) = 3+v;
plot(x,y)
Why loop when you don't have to?
0 个评论
更多回答(1 个)
Azzi Abdelmalek
2014-12-12
for i = 1:100
x(i) = 1 + 2*i;
y(i) = 3 + i;
end
plot(x,y)
2 个评论
Ilham Hardy
2014-12-12
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!
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!