Creating structure array that accumulates

1 Ansicht (letzte 30 Tage)
amateurintraining
amateurintraining am 3 Okt. 2017
Bearbeitet: Cedric am 3 Okt. 2017
How do you create a structure array such that the structure array has five fields that are initially empty then more entries are entered to make the structure array a 1x2 structure? For example, the array has fields: field1, field2, field3, field4, field5. And the first entry is empty. The next command adds another entry with value1,value2,value3,value4,and value5. Basically, the following entries will result in an accumulation of entries. I want to create a function that builds on itself.
Preferably, I would like to see how this is done without if-else statements.
Thank you in advance!
  1 Kommentar
Cedric
Cedric am 3 Okt. 2017
Bearbeitet: Cedric am 3 Okt. 2017
You could just pay attention to the answers that were already given to you, e.g. here where I spent time carefully explaining a couple approaches to you:
and then here for the same question later:
where you can see in the comments under your question that both James and I are wondering why you didn't pay attention to the first answer.

Melden Sie sich an, um zu kommentieren.

Antworten (1)

KSSV
KSSV am 3 Okt. 2017
S = struct ;
% marks in three subjects
S.Maths= [];
S.Physics = [] ;
S.Chemsitry = [] ;
%%five students marks
for i = 1:5
S(i).Maths= rand*100;
S(i).Physics = rand*100 ;
S(i).Chemsitry = rand*100 ;
end

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!

Translated by