Convert char fields of structure into a cell array

9 ビュー (過去 30 日間)
Stefanie
Stefanie 2014 年 2 月 21 日
コメント済み: as a 2021 年 4 月 22 日
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?

採用された回答

Sean de Wolski
Sean de Wolski 2014 年 2 月 21 日
編集済み: Sean de Wolski 2014 年 2 月 21 日
You could also use comma-separted list expansion:
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
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
as a
as a 2021 年 4 月 22 日
I think what u need is B = char(A.a)

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by