matlab struct initialization issue
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Anmol Pardeshi
am 4 Nov. 2020
Kommentiert: Ameer Hamza
am 4 Nov. 2020
I'm trying to initialize a strut which would have fields that represent age groups like <39, 40-49, 50-59 and so on. So I tried the following
x = struct('below39',{},'AG 40 to 49',{}); but it gives me an invalied field name error. I also tried
x = struct('below39',{}); and that worked. I'm not sure why is this an issue. Any insights would eb helpful.
0 Kommentare
Akzeptierte Antwort
Ameer Hamza
am 4 Nov. 2020
Bearbeitet: Ameer Hamza
am 4 Nov. 2020
In MATLAB, the struct fieldnames cannot have spaces. The following will work
x = struct('below39',{},'AG_40_to_49',{})
Read here about rules to for creating a fieldname: https://www.mathworks.com/help/matlab/ref/struct.html#d122e1258552
3 Kommentare
Ameer Hamza
am 4 Nov. 2020
@Anmol Pardeshi, yes. The link mentions the rules to define a fieldname.
@Per Isakson, Thanks for the information.
Weitere Antworten (0)
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!