Sequence of adding numbers

1 回表示 (過去 30 日間)
Akmyrat
Akmyrat 2014 年 6 月 11 日
編集済み: José-Luis 2014 年 6 月 11 日
Hi i have like this question. Lets say i have this code : for i=1:4 C=2+i; end
this gives me this answer: C=3, C=4,C=5,C=6
BUT I want like this answer: C1=3, C2=4, C3=5, C4=6, which is with numbers after letter C. Can anyone help please...thanks :)
  1 件のコメント
Geoff Hayes
Geoff Hayes 2014 年 6 月 11 日
編集済み: Geoff Hayes 2014 年 6 月 11 日

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

採用された回答

Azzi Abdelmalek
Azzi Abdelmalek 2014 年 6 月 11 日
編集済み: Azzi Abdelmalek 2014 年 6 月 11 日
  1 件のコメント
Akmyrat
Akmyrat 2014 年 6 月 11 日
thanks a lot Azzi Abdelmalek...

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

その他の回答 (1 件)

José-Luis
José-Luis 2014 年 6 月 11 日
編集済み: José-Luis 2014 年 6 月 11 日
It might better if you put all your results in one array. Perhaps like this:
ii = 1:4;
C = NaN*ones(size(ii));
for idx = ii
C(idx) = 2 + idx;
end
Creating variables names dynamically, as you seem to want to do, is a bad idea.
Without a loop:
C = 1:4;
C = C + 2;
  1 件のコメント
Akmyrat
Akmyrat 2014 年 6 月 11 日
thanks a lot Jose-Luis..

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

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by