Unable to outerjoin two tables, Error message of 'Left and right key variables have incompatible types'

조회 수: 4 (최근 30일)
Hi, it seems that no matter what I try, my left and right key variables will always be of incompatible types.
It's gotten so frustrating that I literally renamed Table A to have the exact same category names as Table B.
For example, each Table now has the same categories, One, Two, Three, Four, Five, and Six
But for some reason, matlab.mathworks.com keeps saying that 'Ordinal arrays must have the same categories, including their order' - which I believe I already made sure the tables were.
Dear community, what exactly am I doing wrong? Is MATLAB Online not compatible with joining tables?
My version is 2024a - Thanks.
  댓글 수: 1
Jay Coin
Jay Coin 2024년 5월 19일
편집: Jay Coin 2024년 5월 19일
The code I'm using is:
newTaxiALL = outerjoin(TableA,TableB,"Type","left","LeftKeys",["One","Two"],"RightKeys",["One","Two"],"MergeKeys",true);
But I get:

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

답변 (1개)

Peter Perkins
Peter Perkins 2024년 5월 29일
Jay, it's impossible to know what you are doing from what you've posted. outerjoin does work with ordinal key variables, so you will need to post more information.
x = [1;2;3];
g1 = categorical(["a";"b";"b"],Ordinal=true);
g2 = categorical(["c";"c";"d"],Ordinal=true);
t1 = table(x,g1,g2)
t1 = 3x3 table
x g1 g2 _ __ __ 1 a c 2 b c 3 b d
y = [4;5;6];
g1 = categorical(["a";"a";"b"],Ordinal=true);
g2 = categorical(["c";"d";"d"],Ordinal=true);
t2 = table(y,g1,g2)
t2 = 3x3 table
y g1 g2 _ __ __ 4 a c 5 a d 6 b d
outerjoin(t1,t2,"Type","left","LeftKeys",["g1","g2"],"RightKeys",["g1","g2"],"MergeKeys",true)
ans = 3x4 table
x g1 g2 y _ __ __ ___ 1 a c 4 2 b c NaN 3 b d 6

카테고리

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

제품


릴리스

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by