convert cell array to structure with first row as field names

Hi, I have a cell array of 1800 X 920 where first 2 rows are characters. I would like to convert this to a structure with the first row as fields. How to do that?

 採用された回答

Stephen23
Stephen23 2019 年 1 月 8 日
編集済み: Stephen23 2019 年 1 月 8 日

0 投票

Use cell2struct, possibly something like this (where C is your cell array):
S = cell2struct(C(2:end,:),C(1,:),1)

4 件のコメント

Andrei Bobrov
Andrei Bobrov 2019 年 1 月 8 日
Maybe
S = cell2struct(a(2:end,:),a(1,:),2);
dpreuben
dpreuben 2019 年 1 月 9 日
Hi Thanks a lot, In principle this command is working. However, some of my headers have dots and underscores like name.a_b. and it is giving an error as "Invalid field name". How to get around this? Thanks
Stephen23
Stephen23 2019 年 1 月 9 日
You could either pasrse the names to remove any unsupported characters (e.g. regular expression), or simply use genvarname (or its recommended replacements):
dpreuben
dpreuben 2019 年 1 月 9 日
Thanks Stephen

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeCell Arrays についてさらに検索

質問済み:

2019 年 1 月 8 日

コメント済み:

2019 年 1 月 9 日

Community Treasure Hunt

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

Start Hunting!

Translated by