How to get string field from struct with each element separated
3 次查看(过去 30 天)
显示 更早的评论
>> x.name
ans =
'1.33'
ans =
'1.34'
ans =
'1.35'
>> y = [x.name]
y =
'1.331.341.35'
I want to get it like that
y = ['1.33' '1.34' '1.35']
as a matrix with three string elements
2 个评论
Rik
2023-5-26
And if a string vector is a true requirement, the conversion is easy:
x = struct('name',{'1.33','1.34','1.35'}) % reconstruct the data from OP
y = {x.name}
z = string(y)
采纳的回答
gonzalo Mier
2019-5-11
The problem is you are using char instead of string. '1.33' is a vector of char, so if you make a vector of vectors, it compiles them in a row. To make them string you can write "1.33" instead of '1.33' or string('1.33').
1 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Cell Arrays 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!