vertically concatenate two tables with different types of data

조회 수: 21 (최근 30일)
Galo
Galo 2023년 8월 2일
답변: Sugandhi 2023년 8월 21일
I have two tables with the same variables that I want to concatenate vertically.
The problem is that table1 has one of the Variables as double but table2 has the same Variable with cell values, see image
Columns 126 and 128 have the same name in both tables but different type of data which does not allow me to use the following code:
table1 =vertcat(table1, table2);
The error message I'm getting is this one:
Error using tabular/vertcat
Cannot concatenate the table variable 'ACA500300_' because it is a cell in one table and a non-cell in another.
I appreciate any help.
  댓글 수: 2
Dyuman Joshi
Dyuman Joshi 2023년 8월 2일
You can convert the data which is not a cell to a cell and then join them.
Stephen23
Stephen23 2023년 8월 2일
편집: Stephen23 2023년 8월 2일
You could convert the data using e.g. CONVERTVARS or similar.
But the best solution would be to import the data properly in the first place, e.g. by defining the TreatAsMissing option when calling READTABLE.

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

채택된 답변

Sugandhi
Sugandhi 2023년 8월 21일
Hi Galo,
I understand that you want to vertically concatenate two tables with the same variables and different types of data.
The error message you are receiving indicates that you cannot concatenate the table variable 'ACA500300_' because it is a cell in one table and a non-cell in another. To resolve this issue, you can convert the cell values in 'table2' to the double data type before concatenating the tables. Here's an example of how you can achieve this:
% Assuming table1 and table2 are your original tables
% Convert the cell values in table2 to double
table2.ACA500300_ = cell2mat(table2.ACA500300_);
% Concatenate the tables vertically
combinedTable = [table1; table2];
In the above code, 'cell2mat' is used to convert the cell values in the 'ACA500300_' column of 'table2' to the double data type. Then, the tables are concatenated vertically using the square bracket notation '[table1; table2]', and the result is stored in the 'combinedTable' variable.
Make sure that the cell values in 'table2' can be converted to doubles. If there are non-numeric values or missing values in the cells, the conversion may result in an error.
For more understanding, kindly go through following links:
cell2mat:

추가 답변 (0개)

카테고리

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