table2array error

20 ビュー (過去 30 日間)
giulia zanetti
giulia zanetti 2018 年 8 月 1 日
コメント済み: Walter Roberson 2020 年 12 月 7 日
I have a script that reads a text file containing multiple columns, some of which contain text some other contain numbers. I need to sort according to one of the column (making sure the rows stay intact including the 'text' column).
This script starts like this:
t=readtable(startext); aa=table2array(t)
which worked just fine in matlab2015.
I now try to run it in matlab 2017 and I get the following error:
Error using table2array (line 27)
Unable to concatenate the table variables 'Var1' and 'Var2', because their types are cell and double.
Has something changed between matlab version 2015 and 2017, and how do I fix this please?
Thanks
Giulia
  1 件のコメント
Walter Roberson
Walter Roberson 2020 年 12 月 7 日
The "text" -- did it just happen to be something that could be interpreted as a datetime or a as a duration?
Would it be possible for you to attach a short extract of the table, such as three rows that show different representative values of the text?

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

回答 (2 件)

Star Strider
Star Strider 2018 年 8 月 1 日
The table2cell (link) function will convert your table to a cell array. You can then deal with the individual columns separately.

Peter Perkins
Peter Perkins 2018 年 8 月 3 日
table2array wants to create a homogeneous array. It can't do that if the table contains a mix of numeric and text. What would you expect the result to be?
As SS says, you can use table2cell, but I think you need to ask yourself why you want to move your mixed-type data out of a table. That's what tables are for. It may be that you want to extract just the numeric data; you can do that by creating a smaller (narrower) table using a vartype subscript, and then using table2array.
  2 件のコメント
Luisana Rodriguez Sequeira
Luisana Rodriguez Sequeira 2020 年 12 月 7 日
can you elaborate on the vartype subscript needed to sort through the mixed-type data? I have a table which I believe has only numeric data but it was generated through a script code and is very long so I could be mistaken...
Walter Roberson
Walter Roberson 2020 年 12 月 7 日
S = vartype('numeric');
numeric_subset = YourTable{:,S};

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

カテゴリ

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

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by