Working with structures and combining them

4 vues (au cours des 30 derniers jours)
Julia Sandell
Julia Sandell le 20 Fév 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 commentaires
Jurgen
Jurgen le 21 Fév 2013
Sounds like you want to make a class with special methods, e.g. datanew = data1 + data2 where the '+' is overloaded.
Julia Sandell
Julia Sandell le 21 Fév 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.

Connectez-vous pour commenter.

Réponses (1)

Azzi Abdelmalek
Azzi Abdelmalek le 20 Fév 2013
Modifié(e) : Azzi Abdelmalek le 21 Fév 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]

Catégories

En savoir plus sur Variables dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by