Trouble concatenating two tables

5 ビュー (過去 30 日間)
Ryan Callahan
Ryan Callahan 2017 年 4 月 21 日
回答済み: Pufang Yan 2022 年 4 月 1 日
Hello, I am having some issues concatenating two tables. When I try, i get the error "Cannot concatenate the table variable 'Header_Name' because it is a cell in one table and a non-cell in another." I believe this is because in one table the contents of this column are all numbers while in another they have letters. When I look at them, the one with letters has apostrophes around them while the one with numbers doesn't. Can anyone help me with this?

回答 (3 件)

Star Strider
Star Strider 2017 年 4 月 21 日
It will likely be easier to convert the numbers to a cell array of strings.
Something like this will work:
numbers = randi(9, 10, 1);
num_str = num2str(numbers);
num_cell = mat2cell(num_str, ones(10, 1), 1);
Those could probably be combined into a single line. I left them separate to demonstrate how the code works.
Experiment with your table entries to get the result you want.
  2 件のコメント
Ryan Callahan
Ryan Callahan 2017 年 4 月 24 日
My issue with this seems to be that the tables are combinations of cells with numbers and cells with both letters and numbers. So num2str does not seem to work
Star Strider
Star Strider 2017 年 4 月 24 日
My idea is to to convert only the numbers to a cell array of strings, then put them into your table in place of the numbers, leaving your existing cell array of strings unchanged.
Your table then contains only a cell array of strings.

サインインしてコメントする。


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))

Pufang Yan
Pufang Yan 2022 年 4 月 1 日
the columns of 2 tables have different value types. one is numeric, the other is text.

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by