assign cell arrays to struct
조회 수: 43 (최근 30일)
이전 댓글 표시
Dear all,
is it somehow possible to assign cell arrays to the "field" and "value" variables within a struct, like test=struct(field,value) where "field" and "value" are cell arrays ?
Thanks
댓글 수: 0
채택된 답변
Stephen23
2022년 5월 28일
You could use CELL2STRUCT :
fnm = {'hello','world'};
val = {[1,NaN],[1,4,9]};
S2 = cell2struct(val,fnm,2)
or a comma-separated list:
tmp = [fnm;val]; % the orientation is important!
S1 = struct(tmp{:})
댓글 수: 0
추가 답변 (1개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Structures에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!