필터 지우기
필터 지우기

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

조회 수: 6 (최근 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 CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by