Clear Filters
Clear Filters

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

6 views (last 30 days)
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 Comment
Jay Coin
Jay Coin on 19 May 2024
Edited: Jay Coin on 19 May 2024
The code I'm using is:
newTaxiALL = outerjoin(TableA,TableB,"Type","left","LeftKeys",["One","Two"],"RightKeys",["One","Two"],"MergeKeys",true);
But I get:

Sign in to comment.

Answers (1)

Peter Perkins
Peter Perkins on 29 May 2024
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

Categories

Find more on Cell Arrays in Help Center and File Exchange

Products


Release

R2024a

Community Treasure Hunt

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

Start Hunting!