Convert 1x2 double to 1x1 string

8 Ansichten (letzte 30 Tage)
Selva Kumar
Selva Kumar am 14 Jun. 2019
Bearbeitet: dpb am 15 Jun. 2019
I have illustrated my question in the following images.
Data I have - ,
Data I require - ,
How do I convert 1x2 double into 1x1 string?
Thanks in advance

Akzeptierte Antwort

dpb
dpb am 14 Jun. 2019
>> string(sprintf('[%d,%d]',s))
ans =
"[3,7]"
>>
or, with features built into the new string class that mimic VB in many ways--
>> "["+s(1)+","+s(2)+"]"
ans =
"[3,7]"
I think the latter is more of a pain to write than the former, but to each his own...
  3 Kommentare
Stephen23
Stephen23 am 15 Jun. 2019
Simpler:
sprintf("[%d,%d]",s)
% ^ ^ specify the output to be a scalar string.
dpb
dpb am 15 Jun. 2019
Bearbeitet: dpb am 15 Jun. 2019
Good catch, Stephen...let the interpreter do the cast...

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Data Type Conversion finden Sie in Help Center und File Exchange

Produkte


Version

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by