How to assign values to a struct array with fields?
105 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
SeaMoon Kim
am 13 Jan. 2017
Kommentiert: madhan ravi
am 4 Jun. 2019
Is there any way to write down a one-line script for assigning values to a struct array with fields?
x(1).a=1; x(2).a=2;
I'd like to change each value to 10 and 20 respectively. (I mean x(1).a=10, x(2).a=20) [x.a]=[10 20]; <- This causes an error.
0 Kommentare
Akzeptierte Antwort
Vandana Rajan
am 16 Jan. 2017
Bearbeitet: madhan ravi
am 4 Jun. 2019
Hi,
>> x = struct('a',{10,20});
This will create x(1).a = 10 and x(2).a = 20
To modify an already existing structure array,
>> new_val = num2cell([10,20]);
>> [x.a] = new_val{:};
Please see the following link
2 Kommentare
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!