Converting cell to struct with field names

Hi all,
I have a 12x5 cell that I am trying to convert to a structure. I am trying to use the cell2struct function but to no avail.
Right now I have:
structArray = cell2struct(temp, {'a' 'b' 'c' 'd' 'e'}, 5)
Thank you for your help!
Edit1: The first cell in temp{} is a 1x29 cell and the next 4 columns (2:5) are string values
Edit2: The error I get is "Number of field names must match number of fields in new structure."

 채택된 답변

James Tursa
James Tursa 2015년 7월 8일
편집: James Tursa 2015년 7월 8일

1 개 추천

The 3rd argument is the dimension of the cell array to use for the fields, not the number of fields. You've got 5 field names, so I assume you mean to use the 2nd dimension of your 12x5 cell array for the fields. E.g.,
structArray = cell2struct(temp, {'a' 'b' 'c' 'd' 'e'}, 2)

댓글 수: 2

Stephen23
Stephen23 2015년 7월 8일
Indeed, this also described in the documentation:
R J
R J 2015년 7월 8일
편집: R J 2015년 7월 8일
Thank you again James. Much appreciated.
I also just came across this solution as well searching the answers:
names = {'a', 'b', 'c', 'd', 'e'}
tempStruc = cell2struct(temp,names,2);

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Cell Arrays에 대해 자세히 알아보기

태그

질문:

R J
2015년 7월 8일

편집:

R J
2015년 7월 8일

Community Treasure Hunt

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

Start Hunting!

Translated by