Read a column as numbers

6 次查看(过去 30 天)
I have a column with a large number of "NA" and a few numbers. When I import this from a csv file using readtable, matlab reads it as cell array. Even table2array returns a cell array instead of double. How do I read it / convert it as a column of numbers with NaNs for the "NA"s? My code is as below:
data=readtable("Data.csv");
t=table2array(data);
class(t)
ans =
'cell'

采纳的回答

David Hill
David Hill 2020-4-3
This works just fine for me.
data=readmatrix('Data.csv');
  1 个评论
David Hill
David Hill 2020-4-3
opts = detectImportOptions('Data.csv');
opts.DataLines=[2 Inf];
data=readmatrix('Data.csv',opts);

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Data Type Conversion 的更多信息

标签

产品


版本

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by