changing string in a for loop

13 vues (au cours des 30 derniers jours)
Desmond Hutchinson
Desmond Hutchinson le 17 Août 2020
Commenté : Walter Roberson le 17 Août 2020
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.

Réponses (1)

Cris LaPierre
Cris LaPierre le 17 Août 2020
for n = 1:100
str = sprintf("ID_%02d",n);
end
  1 commentaire
Walter Roberson
Walter Roberson le 17 Août 2020
Or
str = compose('ID_%02d', n)

Connectez-vous pour commenter.

Catégories

En savoir plus sur Characters and Strings dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by