changing string in a for loop

13 ビュー (過去 30 日間)
Desmond Hutchinson
Desmond Hutchinson 2020 年 8 月 17 日
コメント済み: Walter Roberson 2020 年 8 月 17 日
I have a script that reads the titles of ID's right now I have the MATLAB set up to read one at a time by typing the ID number as a string.
str = 'ID_01'
I want to add a for loop to change the string to ID_02, ID_03,... to ID_100.

回答 (1 件)

Cris LaPierre
Cris LaPierre 2020 年 8 月 17 日
for n = 1:100
str = sprintf("ID_%02d",n);
end
  1 件のコメント
Walter Roberson
Walter Roberson 2020 年 8 月 17 日
Or
str = compose('ID_%02d', n)

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

カテゴリ

Help Center および File ExchangeCharacters and Strings についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by