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 CenterFile Exchange에서 Tables에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by