Hello,
I want to create a list (1x15 cell) of 15 names (sometimes more than that) with names of following pattern;
AB_01, AB_02, AB_03,....AB_15.
Is there an easy way to do this , in a loop like, rather than type it each.
Thanks

 채택된 답변

Akira Agata
Akira Agata 2019년 6월 18일

0 개 추천

How about the following?
suffix = repmat({'AB_'},15,1);
number = cellstr(num2str((1:15)','%02d'));
output = strcat(suffix,number)';

댓글 수: 3

Simpler:
>> cellstr(num2str((1:15)','AB_%02d'))
ans =
'AB_01'
'AB_02'
'AB_03'
'AB_04'
'AB_05'
'AB_06'
'AB_07'
'AB_08'
'AB_09'
'AB_10'
'AB_11'
'AB_12'
'AB_13'
'AB_14'
'AB_15'
even simpler:
compose('AB_%02d',(1:15)') % >=2016b
Stephen23
Stephen23 2019년 6월 20일
darshani Thotagamuwage's incorrectly accepted "Answer" moved here:
It worked very well. Thanks a lot

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Matrix Indexing에 대해 자세히 알아보기

태그

질문:

2019년 6월 18일

댓글:

2019년 6월 20일

Community Treasure Hunt

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

Start Hunting!

Translated by