assign cell arrays to struct
29 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
René Lampert
am 28 Mai 2022
Beantwortet: Stephen23
am 28 Mai 2022
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 Kommentare
Akzeptierte Antwort
Stephen23
am 28 Mai 2022
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 Kommentare
Weitere Antworten (1)
Siehe auch
Kategorien
Mehr zu Structures finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!