Clear Filters
Clear Filters

Creating structure array that accumulates

2 views (last 30 days)
amateurintraining
amateurintraining on 3 Oct 2017
Edited: Cedric on 3 Oct 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 Comment
Cedric
Cedric on 3 Oct 2017
Edited: Cedric on 3 Oct 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.

Sign in to comment.

Answers (1)

KSSV
KSSV on 3 Oct 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

Categories

Find more on Data Types in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!