assign cell arrays to struct
31 次查看(过去 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!