Quick question about the loop

How do I collect values that were done through the loop?
For example,
M=10:40
for i=0:30;
i=i+1;
A=10+M(i);
end
and the answer just comes out as A=50, instead of A=20:50. What would I do in order to collect the 30 values as matrix?

 採用された回答

Andrejus
Andrejus 2014 年 10 月 19 日
編集済み: Andrejus 2014 年 10 月 19 日

0 投票

try this:
M=10:40
for i=0:30;
i=i+1;
A(i)=10+M(i);
end

1 件のコメント

Jan
Jan 2014 年 10 月 19 日
Do not increase the value of the loop copunter inside loop.

サインインしてコメントする。

その他の回答 (1 件)

Jan
Jan 2014 年 10 月 19 日

0 投票

M = 10:40
A = M + 10;

カテゴリ

ヘルプ センター および File ExchangeLoops and Conditional Statements についてさらに検索

タグ

質問済み:

JK
2014 年 10 月 19 日

回答済み:

Jan
2014 年 10 月 19 日

Community Treasure Hunt

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

Start Hunting!

Translated by