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

Maybe
S = cell2struct(a(2:end,:),a(1,:),2);
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
You could either pasrse the names to remove any unsupported characters (e.g. regular expression), or simply use genvarname (or its recommended replacements):
Thanks Stephen

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Cell 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