Merging two structures of same lengths, different field names

3 次查看(过去 30 天)
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?

采纳的回答

Walter Roberson
Walter Roberson 2011-3-15
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 个评论
Anathea Pepperl
Anathea Pepperl 2011-3-16
Thank you! Used the CATSTRUCT function, and it worked perfectly!

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Data Type Conversion 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by