Borrar filtros
Borrar filtros

Creating structure array that accumulates

2 visualizaciones (últimos 30 días)
amateurintraining
amateurintraining el 3 de Oct. de 2017
Editada: Cedric el 3 de Oct. de 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 comentario
Cedric
Cedric el 3 de Oct. de 2017
Editada: Cedric el 3 de Oct. de 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.

Iniciar sesión para comentar.

Respuestas (1)

KSSV
KSSV el 3 de Oct. de 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

Categorías

Más información sobre Data Types en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by