Why can't I plot such an easy graph?

3 ビュー (過去 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 Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by