adding empty numerical fields in structure array
42 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Octavian
am 25 Dez. 2014
Bearbeitet: per isakson
am 25 Dez. 2014
Dear All,
I am sure this is trivial for you wizzes. I have a structure A with fields A.field1,A.field2, A.field3, with fields 1 and 2 cell arrays, and field3 numerical double array. How do I add two empty, numerical double, fields named 'field4' and 'field5', to A, that I can fill later separately?
Thank you,
Octavio
0 Kommentare
Akzeptierte Antwort
per isakson
am 25 Dez. 2014
Bearbeitet: per isakson
am 25 Dez. 2014
Yes, that's simple:
A.field4 = [];
A.field5 = [];
 
In response to comment
>> clear A
>> A.f1=1;
>> A.f2=2;
>> A.field5 = [];
>> A.field4 = [];
>> A
A =
f1: 1
f2: 2
field5: []
field4: []
>>
So far so good.
>> A=[A,A]
A =
1x2 struct array with fields:
f1
f2
field5
field4
f3
>> A.f4 = []
Incorrect number of right hand side elements in dot name assignment.
Missing [] around left hand side is a likely cause.
Ok, I missed that you have a struct array
>> A(1).f4 = []
A =
1x2 struct array with fields:
f1
f2
field5
field4
f3
f4
>> A(1).f4
ans =
[]
>> A(2).f4
ans =
[]
Or better
>> [A.f5] = deal([])
A =
1x2 struct array with fields:
f1
f2
field5
field4
f3
f4
f5
1 Kommentar
per isakson
am 25 Dez. 2014
moved from an answer by per isakson
Dear Per,
Trying A.field4 = [];
I get the error:
Incorrect number of right hand side elements in dot name assignment. Missing [] around left hand side is a likely cause. Please advise
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!