Error: Left and right key variables are not comparable because one is a non-cell
Mostrar comentarios más antiguos
Hi,
I have two tables which I want to join using the join() function. However, when I try to join them together like so:
load questionnaire_table.mat
load DFA_PCA_table.mat
load high_dfa_ID_table.mat
load PCA_table.mat
Full_high_data_set_table = join(questionnaire_table,DFA_PCA_table)
I get this error:
Left and right key variables 'ID' and 'ID' are not comparable because one is a non-cell.
This issue didnt arise with other tables which I joined like the following:
DFA_PCA_table = join(high_dfa_ID_table,PCA_table)
Any idea why that is the case?
Thanks!
EDIT: mat files reattached, variables loaded and code run to try to recreate the error
6 comentarios
Cris LaPierre
el 28 de Jul. de 2022
Editada: Cris LaPierre
el 28 de Jul. de 2022
I am able to run your code without any errors. Have you shared the code you are running? Have you specified left and right keys?
load lil_brain_tables.mat
Full_high_data_set_table = join(questionnaire_table,DFA_PCA_table)
DFA_PCA_table = join(high_dfa_ID_table,PCA_table)
lil brain
el 28 de Jul. de 2022
Cris LaPierre
el 28 de Jul. de 2022
What version of MATLAB are you using?
You can also run code here in Answers, like I did in my post. Upload your data and then paste in the necessary code to recreate the error here. That will let us see both the code and the complete error message.
lil brain
el 28 de Jul. de 2022
Image Analyst
el 28 de Jul. de 2022
To avoid spam, there may be a limit on how many posts a new user can make per day (10 I think). Try again tomorrow.
Cris LaPierre
el 28 de Jul. de 2022
Editada: Cris LaPierre
el 28 de Jul. de 2022
You might be able to edit your original question, too, as the data and some code have already been added there. I've edited it to re-add the mat files and have run the code you shared.
Respuestas (1)
Hi lil brain,
I understand from your issue that you are unable to join two tables, that have a common column named “ID”, and you are prompted with an error you mentioned above.
From MATLAB R2022a onwards, the “join” function can handle key variables with different data types (like string arrays and cell arrays of character vectors). So, your original code should work as expected without any modifications in MATLAB R2022a and later versions.
However, in MATLAB R2021b and earlier versions, the “join” function requires key variables to have the same data type. If you encounter the error "Left and right key variables 'ID' and 'ID' are not comparable because one is a non-cell", it means that the 'ID' column in one table is a cell array of character vectors while in the other table it's a string array.
You can resolve this issue by converting the 'ID' column to the same data type in both tables. If the 'ID' column is an alphanumeric string, you should convert the string array to a cell array of character vectors using the “cellstr” function.
Here is the modified code where I have simply converted the string variables to cell array.
load questionnaire_table.mat
load DFA_PCA_table.mat
load high_dfa_ID_table.mat
load PCA_table.mat
% Convert 'ID' column to cell array of character vectors if it's a string array in questionnaire_table
if isstring(questionnaire_table.ID)
questionnaire_table.ID = cellstr(questionnaire_table.ID);
end
% Now you can join the tables
Full_high_data_set_table = join(questionnaire_table,DFA_PCA_table)
% Convert 'ID' column to cell array of character vectors if it's a string array in PCA_table
if isstring(PCA_table.ID)
PCA_table.ID = cellstr(PCA_table.ID);
end
% Now you can join the tables
DFA_PCA_table = join(high_dfa_ID_table,PCA_table)
Alternatively, you can upgrade to any newer version or use MATLAB online.
Hope this helps and resolves your issue.
Thanks
Gyan
Categorías
Más información sobre Tables en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!