How do I print the following for loop as A1, A2, A3, A4?
3 views (last 30 days)
Show older comments
Kartik Bharadwaj
on 30 Aug 2017
Commented: Stephen23
on 30 Aug 2017
for i = 1:4
print A%d, i
end
0 Comments
Accepted Answer
Star Strider
on 30 Aug 2017
Use fprintf or sprintf.
Try this:
for i = 1:4
fprintf('A%d\n', i)
end
0 Comments
More Answers (2)
Walter Roberson
on 30 Aug 2017
Edited: Walter Roberson
on 30 Aug 2017
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).'
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!