Reformat numbers in table

조회 수: 6 (최근 30일)
DavidL88
DavidL88 2021년 2월 5일
댓글: DavidL88 2021년 2월 5일
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?

채택된 답변

Maximilian Schönau
Maximilian Schönau 2021년 2월 5일
% leading zero in the format specifier specifies leading zeros in your string
t.Var1 = "Subject" + string(num2str(t.Var1,'%03i'));
  댓글 수: 1
DavidL88
DavidL88 2021년 2월 5일
Worked, thanks!

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Seismology에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by