Convert 1x2 double to 1x1 string

8 次查看(过去 30 天)
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

采纳的回答

dpb
dpb 2019-6-14
>> 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 个评论
Stephen23
Stephen23 2019-6-15
Simpler:
sprintf("[%d,%d]",s)
% ^ ^ specify the output to be a scalar string.
dpb
dpb 2019-6-15
编辑:dpb 2019-6-15
Good catch, Stephen...let the interpreter do the cast...

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Data Type Conversion 的更多信息

产品


版本

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by