Merging two structures of same lengths, different field names

3 visualizaciones (últimos 30 días)
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?

Respuesta aceptada

Walter Roberson
Walter Roberson el 15 de Mzo. de 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 comentarios
Anathea Pepperl
Anathea Pepperl el 16 de Mzo. de 2011
Thank you! Used the CATSTRUCT function, and it worked perfectly!
Walter Roberson
Walter Roberson el 16 de Mzo. de 2011
And thanks to Jos for writing the function.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Data Type Conversion en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by