Merging two structures of same lengths, different field names

2 ビュー (過去 30 日間)
Anathea Pepperl
Anathea Pepperl 2011 年 3 月 15 日
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!
Walter Roberson
Walter Roberson 2011 年 3 月 16 日
And thanks to Jos for writing the function.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeData Type Conversion についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by