Reformat numbers in table

3 vues (au cours des 30 derniers jours)
DavidL88
DavidL88 le 5 Fév 2021
Commenté : DavidL88 le 5 Fév 2021
Hi
I have a table and in one column there is a row of subject numbers going from one digit up to three digits.
t.Var1 =
5
88
194
I would like to reformat them so they are like this i.e. 'Subject' at beginning and all number with 3 digits (1 and 2 digit numbers should have 00 and 0 at begining respectively to make 3 digits.)
t.Var1 =
Subject005
Subject088
Subject194
Could someone advise how to do this?

Réponse acceptée

Maximilian Schönau
Maximilian Schönau le 5 Fév 2021
% leading zero in the format specifier specifies leading zeros in your string
t.Var1 = "Subject" + string(num2str(t.Var1,'%03i'));
  1 commentaire
DavidL88
DavidL88 le 5 Fév 2021
Worked, thanks!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Seismology dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by