How do I print the following for loop as A1, A2, A3, A4?

1 回表示 (過去 30 日間)
Kartik Bharadwaj
Kartik Bharadwaj 2017 年 8 月 30 日
コメント済み: Stephen23 2017 年 8 月 30 日
for i = 1:4
print A%d, i
end

採用された回答

Star Strider
Star Strider 2017 年 8 月 30 日
Use fprintf or sprintf.
Try this:
for i = 1:4
fprintf('A%d\n', i)
end

その他の回答 (2 件)

Jan
Jan 2017 年 8 月 30 日
編集済み: Jan 2017 年 8 月 30 日
for i = 1:4
fprintf('A%d, ', i);
end
Or without a loop:
fprintf('A%d, ', 1:4);
Or omit the last comma:
fprintf('A%d, A%d, A%d, A%d\n', 1:4);
Do not forget:
disp('A1, A2, A3, A4')
;-)

Walter Roberson
Walter Roberson 2017 年 8 月 30 日
編集済み: Walter Roberson 2017 年 8 月 30 日
cellstr( num2str( (1:4).', 'A%d') )
If you have R2017a or later, then consider
"A" + (1:4).'
If you have R2016b, then consider
string('A') + (1:4).'

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by