table2array error
21 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaire
Walter Roberson
le 7 Déc 2020
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?
Réponses (2)
Star Strider
le 1 Août 2018
The table2cell (link) function will convert your table to a cell array. You can then deal with the individual columns separately.
0 commentaires
Peter Perkins
le 3 Août 2018
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 commentaires
Luisana Rodriguez Sequeira
le 7 Déc 2020
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
le 7 Déc 2020
S = vartype('numeric');
numeric_subset = YourTable{:,S};
Voir également
Catégories
En savoir plus sur Tables dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!