Effacer les filtres
Effacer les filtres

Is it possible to combine two structures saved in two different .mat files?

7 vues (au cours des 30 derniers jours)
bio lim
bio lim le 7 Août 2015
Commenté : bio lim le 7 Août 2015
I have two structures, both named 'data' with 17 same fields. They are basically measured data of two different dates, and I would like two combine these two. In order words, what I want is:
First .mat file: data = 1 x 85 struct array with 17 fields.
Second .mat file: data = 1 x 15 struct array with 17 fields.
---------------------------------------------------------------
Combined .mat file: data = 1 x 100 struct array with 17 fields.
If possible, I would like to avoid writing a script and rather use GUI. I also think it is possible two combine the two structures by loading both files (renaming one of them). I also would like to avoid this method.
Thanks.
  2 commentaires
Walter Roberson
Walter Roberson le 7 Août 2015
Are the fields in exactly the same order between the two files?
bio lim
bio lim le 7 Août 2015
Modifié(e) : bio lim le 7 Août 2015
Yes, they are exactly the same.

Connectez-vous pour commenter.

Réponse acceptée

Azzi Abdelmalek
Azzi Abdelmalek le 7 Août 2015
Look at this example
q=num2cell(1:2)
p=num2cell(1:3)
a=struct('a',q,'b',q)
b=struct('a',p,'b',p)
c=[a b]
  3 commentaires
Walter Roberson
Walter Roberson le 7 Août 2015
Modifié(e) : Walter Roberson le 7 Août 2015
datacell1 = load('First file.mat');
datacell2 = load('Second file.mat');
combined.data = [datacell1.data, datacell2.data];
save('Combined file.mat', '-struct', 'combined')
bio lim
bio lim le 7 Août 2015
Thanks, Walter. Works like charm :)

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Structures dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by