Merging two structures of same lengths, different field names

조회 수: 2 (최근 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!
Walter Roberson
Walter Roberson 2011년 3월 16일
And thanks to Jos for writing the function.

댓글을 달려면 로그인하십시오.

추가 답변 (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