table2array error

20 visualizaciones (últimos 30 días)
giulia zanetti
giulia zanetti el 1 de Ag. de 2018
Comentada: Walter Roberson el 7 de Dic. de 2020
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 comentario
Walter Roberson
Walter Roberson el 7 de Dic. de 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?

Iniciar sesión para comentar.

Respuestas (2)

Star Strider
Star Strider el 1 de Ag. de 2018
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 el 3 de Ag. de 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 comentarios
Luisana Rodriguez Sequeira
Luisana Rodriguez Sequeira el 7 de Dic. de 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
Walter Roberson el 7 de Dic. de 2020
S = vartype('numeric');
numeric_subset = YourTable{:,S};

Iniciar sesión para comentar.

Categorías

Más información sobre Tables en Help Center y File Exchange.

Etiquetas

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by