Merging two structures of same lengths, different field names

3 vues (au cours des 30 derniers jours)
Anathea Pepperl
Anathea Pepperl le 15 Mar 2011
I have a structure array called Xdata and a cell array called Ydata of the same lengths. Each Ydata depends on the date that Xdata was taken, so I used arrayfun in order to generate Ydata. That code looks like this:
Ydata = arrayfun(@(a) FindIncline(a.date), Xdata, 'UniformOutput', false);
Is there a way to use arrayfun so that, instead of assigning to Ydata, I can assign directly into Xdata?
If not, how do I merge the two together?
I can use the following:
for i = 1: length(Xdata),
Xdata(i).f1 = Ydata{i}.f1;
Xdata(i).f2 = Ydata{i}.f2;
end
to add the contents of Ydata into Xdata, but I'd like to have more efficient code.
Any suggestions?

Réponse acceptée

Walter Roberson
Walter Roberson le 15 Mar 2011
I seem to recall that there is a structure merging contribution in the Matlab File Exchange (FEX)
If not then if you convert to cell, append the cell parts, and convert back, you will have achieved the merge.
  4 commentaires
Anathea Pepperl
Anathea Pepperl le 16 Mar 2011
Thank you! Used the CATSTRUCT function, and it worked perfectly!
Walter Roberson
Walter Roberson le 16 Mar 2011
And thanks to Jos for writing the function.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Data Type Conversion 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