How to convert struct filed to cell array before R2016a?

1 回表示 (過去 30 日間)
Mr M.
Mr M. 2016 年 8 月 11 日
回答済み: Sindhuja Parimalarangan 2016 年 8 月 12 日
How to convert struct filed to cell array before R2016a? I want to convert mystruct(:).name to {'name1','name2','name3'}, where mystruct(1).name = 'name1', etc.

採用された回答

Sindhuja Parimalarangan
Sindhuja Parimalarangan 2016 年 8 月 12 日
Hi
You could use the comma-separated list expansion
For example, if you had a struct with 3 fields as follows:
>>s(1).category = 'tree1';s(1).height = 37.4; s(1).name = 'birch1';
>>s(2).category = 'tree2';s(2).height = 37.5; s(2).name = 'birch2';
To convert the 'name' fields into a cell array A,
>>A = {S(:).name}
In your case, it would be:
>> myCell = {mystruct(:).name}

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeStructures についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by