필터 지우기
필터 지우기

Way to concatenate tables with some but not all variables in common?

조회 수: 9 (최근 30일)
Gabe
Gabe 2017년 7월 6일
편집: Sterling Baird 2020년 9월 5일
I am trying to concatenate several similar tables that have mostly the same variables, but a few differences. In the cases of different variables I'd want to pad values with NaN.
For example:
A =
var1 var2
____ ____
1 2
B =
var1 var3
____ ____
1 3
C=somefunction(A,B)
C =
var1 var2 var3
____ ____ ____
1 2 NaN
1 NaN 3
Is there any canned function that does this?
  댓글 수: 2
Peter Perkins
Peter Perkins 2017년 7월 7일
Gabe, hacking outerjoin to do vertical concatenation is super clever, but I think it isn't going to work for you, because the common variables that you'd use as the "key" (Var1 in your example) have values in common. At least in your example they do.
I think you'd be safer just finding the setxor of the two lists of var names, and creating the vars you need using NaNs.

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

답변 (1개)

Sterling Baird
Sterling Baird 2020년 9월 5일
편집: Sterling Baird 2020년 9월 5일
Here is a "canned" FEX function (tblvertcat) I just refactored using some old code I wrote a while ago and based on a MATLAB Answers post. It can be used for an arbitrary number of tables, and supports double, char, cell, struct, etc.

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by