Why can't I plot such an easy graph?

조회 수: 1 (최근 30일)
Moj
Moj 2014년 12월 12일
댓글: Stephen23 2014년 12월 18일
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
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?

추가 답변 (1개)

Azzi Abdelmalek
Azzi Abdelmalek 2014년 12월 12일
for i = 1:100
x(i) = 1 + 2*i;
y(i) = 3 + i;
end
plot(x,y)
  댓글 수: 2
Moj
Moj 2014년 12월 12일
but it doesn't work when we have no integer number for i.
for i = 7e-5:1e-5:3e-4
x(1,:) = 1 + 2*i;
y(1,:) = 3 + i;
end
plot(x,y)
Ilham Hardy
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. 1. "i" is actually square-root of -1
  2. 2. "i" and "1" is quite difficult for human eyes to distinguish!

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by