how to make numbering near "a" like: a1, a2, an

Hi,
Could you please tell me how to increase number near "a" so it could look like this:
b = 1; "ab = something" b = b + 1; ...
a1 = something; a2 = something; ... an = something;

 採用された回答

Arthur
Arthur 2012 年 11 月 25 日

3 投票

Please don't use dynamic variable names, matlab has plenty of options to store your data in a better way. Use cells or structs.

3 件のコメント

Jan
Jan 2012 年 11 月 25 日
I second Arthur's suggestion: Do not insert an index in the name of the variable. While this might look useful for "a1", "a2", "a3", it becomes a horror for ..."a117", "a118" etc. Using "a{1}", "a{2}" is much smarter.
Matt Fig
Matt Fig 2012 年 11 月 25 日
There is a run of these requests recently.
Image Analyst
Image Analyst 2012 年 11 月 25 日
If the "a" are being assign to simple numbers (not to strings, structures, cells, etc.), then using a simple numerical array is best and easiest:
for k = 1 : 118
a(k) = b; % a is floating point array, unless you explicitly cast b to an integer type.
b = b + 1; % Whatever.....
end

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

その他の回答 (1 件)

moulay
moulay 2012 年 11 月 25 日

0 投票

for example_:
% for i=1:2:5
b=['a_' num2str(i)]
end
is that waht are u looking for?

カテゴリ

ヘルプ センター および File ExchangeMatrix Indexing についてさらに検索

製品

タグ

質問済み:

2012 年 11 月 25 日

コメント済み:

2023 年 6 月 21 日

Community Treasure Hunt

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

Start Hunting!

Translated by