problem to concatenate table due to "cell and non cell" error
Mostra commenti meno recenti
Hello,
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);
Thanks!
4 Commenti
Walter Roberson
il 18 Mag 2020
Change
Ge_table(:,4) = {1};
Ge_table.Properties.VariableNames{4} = 'detector';
to
Ge_table.detector = ones(height(Ge_table),1);
Adam Danz
il 18 Mag 2020
What's preventing the first version from working, though?
T = array2table(rand(5,4));
T(:,4) = {1}
Walter Roberson
il 18 Mag 2020
I hypothesize that one of the tables already had four columns.
Adam Danz
il 18 Mag 2020
Hmmm.... but the variableNames being assigned only contain 3 values which would throw an error.
Perhaps we aren't seeing the full code.
Risposta accettata
Più risposte (1)
Gabor
il 20 Mag 2021
0 voti
I would add to check the missmatching table variables by comparing them by for eg.:
class(Table1.Column_name(1))
class(Table2.Column_name(1))
1 Commento
Adam Danz
il 20 Mag 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.
Categorie
Scopri di più su Tables in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!