Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Working with structures and combining them

Asked by Julia Sandell on 20 Feb 2013

I have a bunch of data that was saved in individual data structures. I would like to combine them so I can work the dataset as whole. See example below:

data1 =

           lambda: [1024x1 double]
             data: [1024x8 double]
              err: [1024x8 double]
               fl: [1024x8 double]
            flerr: [1024x8 double]
               Ns: 1
               Nd: 8
               Nw: 1024
                t: [0.0500 0.0500 0.0500]
                P: 0
              z_s: 0
             r_sd: [0.1200 0.1800 0.2400 0.3000 0.4000 0.5000 0.6000 0.8000]
            fr_sd: [0.1200 0.1800 0.2400 0.3000 0.4000 0.5000 0.6000 0.8000]
       data_files: {[1x144 char]}
    data_file_map: [3x2 double]
      corrections: {{6x2 cell}}
           sample: {'D2_postPDT_abdo. wall_ref_1(1)'}
         n_frames: 4

data2 =

           lambda: [1024x1 double]
             data: [1024x8 double]
              err: [1024x8 double]
               fl: [1024x8 double]
            flerr: [1024x8 double]
               Ns: 1
               Nd: 8
               Nw: 1024
                t: [0.0500 0.0500 0.0500]
                P: 0
              z_s: 0
             r_sd: [0.1200 0.1800 0.2400 0.3000 0.4000 0.5000 0.6000 0.8000]
            fr_sd: [0.1200 0.1800 0.2400 0.3000 0.4000 0.5000 0.6000 0.8000]
       data_files: {[1x139 char]}
    data_file_map: [3x2 double]
      corrections: {{6x2 cell}}
           sample: {'D2_postPDT_Aorta_ref_1(1)'}
         n_frames: 4

I want to create a new data structure that would combine these two and would look something like this:

totdata =

           lambda: [1024x1 double]
             data: [1024x9x2 double]
              err: [1024x9x2 double]
               fl: [1024x9x2 double]
            flerr: [1024x9x2 double]
               Ns: 2
               Nd: 9
               Nw: 1024
                t: [1x4 double]
                P: [2x1 double]
              z_s: [2x1 double]
             r_sd: [0.1200 0.1800 0.2400 0.3000 0.4000 0.5000 0.6000 0.8000]
            fr_sd: [0.1200 0.1800 0.2400 0.3000 0.4000 0.5000 0.6000 0.8000]
       data_files: {2x1 cell}
    data_file_map: [4x2 double]
      corrections: {1x2 cell}
           sample: {2x1 cell}
         n_frames: [4 4]

I have about 100 of such data files, any suggestions on how to handle this?

Many many thanks in advance!

4 Comments

Azzi Abdelmalek on 20 Feb 2013

You have to explain how data will be stored in the new struct variable

Jurgen on 21 Feb 2013

Sounds like you want to make a class with special methods, e.g. datanew = data1 + data2 where the '+' is overloaded.

Julia Sandell on 21 Feb 2013

First off :

data: [1024x8 double] % from first variable data: [1024x8 double] % from second variable How did you get ?

   data: [1024x9x2 double]

I got this by the following: tdata=cat(3,data1.data,data2.data);

But I really don't have to do this for each of the 100 data structures I have that each have 18 fields. What I want is to combine in the data.

I want to create a new data structure that has in say the 'data' field, the 'fl' field not just one sample, but all samples. How would I do this? The suggested solution does not give this.

Julia Sandell

Products

No products are associated with this question.

1 Answer

Answer by Azzi Abdelmalek on 20 Feb 2013
Edited by Azzi Abdelmalek on 21 Feb 2013

Let us guess, Maybe you want something like this

data1=struct('data',num2cell(1:10))
data2=struct('data',num2cell(11:20))
totdata=[data1 data2]

%or

totdata=[data1 ;data2]

0 Comments

Azzi Abdelmalek

Contact us