problem to concatenate table due to "cell and non cell" error

98 views (last 30 days)
I have a script that reads 2 TXT files to two tables (one is significantly larger than the other). then I add both table the columb 'detector' to the 4th column (both tables structure is identicle, and supposed to be the same types of variable to all columns). for some reason I'm getting this error : "Cannot concatenate the table variable 'detector' because it is a cell in one table and a non-cell in another."
the script works fine with smaller files.
is matlab chaneging the type of the variable due to the size?
this is the script:
Ge_table = readtable(hpge_file); %
Ge_table.Properties.VariableNames = {'time_stamp', 'energy','time_adjusted'};
scint_table = readtable(pmt_file); %
scint_table.Properties.VariableNames = {'time_stamp', 'energy','time_adjusted'};
Ge_table(:,4) = {1};
Ge_table.Properties.VariableNames{4} = 'detector';
scint_table(:,4) = {0};
scint_table.Properties.VariableNames{4} = 'detector';
coince_table = vertcat(Ge_table, scint_table);
Adam Danz
Adam Danz on 18 May 2020
Hmmm.... but the variableNames being assigned only contain 3 values which would throw an error.
Perhaps we aren't seeing the full code.

Sign in to comment.

Accepted Answer

Adam Danz
Adam Danz on 18 May 2020
Edited: Adam Danz on 18 May 2020
One possibility is that the cell / non-cell mismatch is being caused by a different column in the table.
Here are two ways you can quickly see if there's any mismatches in variable types between two columns.
1) look at the first few rows of each table.
If you're unsure what to look for, leave a comment that contains the content of those two outputs.
2) Look at the variable classes for each column, for each table. Do they match?
GeTblClasses = varfun(@class,Ge_table,'OutputFormat','cell');
scintTblClasses = varfun(@class,scint_table,'OutputFormat','cell');
sani on 18 May 2020
so, what I did was, instead of adding a new column to the table, I created a new table of zeros in the length of my table and than concatenate them. now it works:)

Sign in to comment.

More Answers (1)

Gabor on 20 May 2021
I would add to check the missmatching table variables by comparing them by for eg.:
  1 Comment
Adam Danz
Adam Danz on 20 May 2021
That's what step 2 does in my answer except it checks the class of all columns in the table rather than just the first column.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!