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

조회 수: 44 (최근 30일)
sani
sani 2020년 5월 18일
댓글: Adam Danz 2021년 5월 20일
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
Walter Roberson
Walter Roberson 2020년 5월 18일
I hypothesize that one of the tables already had four columns.
Adam Danz
Adam Danz 2020년 5월 18일
Hmmm.... but the variableNames being assigned only contain 3 values which would throw an error.
Perhaps we aren't seeing the full code.

댓글을 달려면 로그인하십시오.

채택된 답변

Adam Danz
Adam Danz 2020년 5월 18일
편집: Adam Danz 2020년 5월 18일
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.
head(Ge_table)
head(scint_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');
  댓글 수: 14
sani
sani 2020년 5월 18일
thanks for the explenation!
I don't think this will help in my case, since I'm able to load the files to tables, and even to add the 3rd column.
for some reason that I don't understand it gives different types for the same operation for each data set.
my suspition is that in order to utikize the memory better it save the 4th column in the larger file as char. from what that I recall, char takes 8 bits and float (thats how it define the 4th column in the other data set) takes 32 bits.
I wondering if there is a way to inforce it to save it as float? or, maybe I can define another X by one table (where X is the number of line in the data set table) and then join them?
sani
sani 2020년 5월 18일
SOLVED!
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:)

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Gabor
Gabor 2021년 5월 20일
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
Adam Danz
Adam Danz 2021년 5월 20일
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.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by