combine number from cell array and letter to a string

1 Ansicht (letzte 30 Tage)
Dongyan Zhu
Dongyan Zhu am 18 Jun. 2021
Kommentiert: Dongyan Zhu am 18 Jun. 2021
Now I have a cell array contaning some numbers:
SequencePreview =
1×3 cell array
{'3'} {'1'} {'4'}
Then I want to get a string showed using for loop as below:
'V3-V1-V4'
Does someone have an idea? Thank you!

Akzeptierte Antwort

Stephen23
Stephen23 am 18 Jun. 2021
Bearbeitet: Stephen23 am 18 Jun. 2021
C = {'3','1','4'}
C = 1×3 cell array
{'3'} {'1'} {'4'}
S = join(strcat("V",C),"-") % output = string
S = "V3-V1-V4"
or the old-fashioned way:
S = sprintf('-V%s',C{:}); % output = char
S = S(2:end)
S = 'V3-V1-V4'

Weitere Antworten (0)

Kategorien

Mehr zu Numeric Types finden Sie in Help Center und File Exchange

Produkte


Version

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by