Merge two matrices of different length with respect to a date
조회 수: 1 (최근 30일)
이전 댓글 표시
Hi,
I want to merge these two datasets. It is slightly different with this one: https://uk.mathworks.com/matlabcentral/answers/316710-can-i-merge-two-matrices-of-different-length-with-respect-to-a-date-column-contained-in-both
Instead of trying to get the combination of the two based on the shortest length, I want to instead maintain the longest matrix and give a NaN values for the shortest matrix. This is my data:
A = [
2000 1
2001 1
2002 1
2003 1
2004 1
2005 1
2006 1
2007 1
2008 1
2009 1
2010 1
];
B = [
2005 3
2006 3
2007 3
2008 3
2009 3
2010 3
];
I am expecting the output to be like this one below:
AB = [
2000 1 NaN
2001 1 NaN
2002 1 NaN
2003 1 NaN
2004 1 NaN
2005 1 3
2006 1 3
2007 1 3
2008 1 3
2009 1 3
2010 1 3
];
How can we do this?
댓글 수: 0
채택된 답변
Andrei Bobrov
2019년 7월 27일
AB = outerjoin(array2table(A,'v',{'years','dataA'}),...
array2table(B,'v',{'years','dataB'}),'MergeKeys',true)
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Structures에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!