-1

I'm very new to matlab and have a question:

I have a file which contains a structA . This struct contains than also substructA1, substruct A2, substructA3 , substructA4 .

Each of this substructs contains a variable myVariable of 100 elements.

Now I would like to iterate over all this structs and copy all the elements of the variable myVariable into a new file so I will have in one row 400 values

I started like this:

structA = struct('substructA1','substructA2','substructA3','substructA4');

  for field = fieldnames(structA)
  // How to continoue from this point ?

What is the simplest way?

JohnDoe
  • 825
  • 1
  • 13
  • 31

2 Answers2

0

Just use struct2array:

structA = struct(... 
'substructA1',rand(1,100),...
'substructA2',rand(1,100),...
'substructA3',rand(1,100),...
'substructA4',rand(1,100));

data=struct2array(structA)

have fun

marco wassmer
  • 421
  • 2
  • 8
0

you can assess each substructs by structA.(field{i}) check this link Iterating through struct fieldnames in MATLAB

dushk
  • 36
  • 1