Convert char fields of structure into a cell array
12 次查看(过去 30 天)
显示 更早的评论
I have a structure with fields like
A(1).a='A01'
A(2).a='A02'
A(3).a='A03'
Now I would like to convert this structure into a cell array. I tried with
B=[A.a]
B =
A01A02A03
That is not, what I need. I would like to have:
B =
'A01'
'A02'
'A03'
Is there an easy way, or do I need to write a loop for that?
0 个评论
采纳的回答
Sean de Wolski
2014-2-21
编辑:Sean de Wolski
2014-2-21
ac = {A(:).a}
Similar to what you did above, but rather than concatenating the strings with [], concatenate them into cells with {}.
5 个评论
Marie-Claude Boisvert
2017-9-7
编辑:Marie-Claude Boisvert
2017-9-7
Hi, I tried it and got a new string vector :) super , but do you know how to change it directly in the Structure (A here) ? Thanks
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!