Convert 1x2 double to 1x1 string
9 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I have illustrated my question in the following images.
Data I have -
, ![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/224605/image.jpeg)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/224604/image.jpeg)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/224605/image.jpeg)
Data I require -
, ![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/224607/image.jpeg)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/224606/image.jpeg)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/224607/image.jpeg)
How do I convert 1x2 double into 1x1 string?
Thanks in advance
0 commentaires
Réponse acceptée
dpb
le 14 Juin 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 commentaires
Stephen23
le 15 Juin 2019
Simpler:
sprintf("[%d,%d]",s)
% ^ ^ specify the output to be a scalar string.
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Data Type Conversion 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!