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

5 次查看(过去 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