Chuhang Yin
Chuhang Yin

Reputation: 41

Matlab cannot read "numeric" field from csv

I am trying to read a csv file into Matlab using the following command

data=csvread('/econ/research/rd123/RAIS/Chuhang/data/final_samples/growth_regs_RandI_ALL.csv',1,0);

But matlab produced the following message:

{Error using dlmread (line 138) Mismatch between file and format string. Trouble reading 'Numeric' field from file (row number 1, field number 1) ==> "00000000000272",440,"65","13007",1995,6586,.1776316,-.1045213,.2821529,.0000105,.0002363,.0378644,.0078976\n

Error in csvread (line 47) m=dlmread(filename, ',', r, c);

Error in import_all_mfn (line 13) data=csvread('/econ/research/rd123/RAIS/Chuhang/data/final_samples/growth_regs_RandI_ALL.csv',1,0);

Does anyone know what the problem might be? Thanks in advance!

-Chuhang

Upvotes: 4

Views: 12756

Answers (2)

srkn sltrk
srkn sltrk

Reputation: 418

Use

 T = readtable(filename);
 firstcolumn = T{:,1};

This function reads all table but you must use indices as cells.

Also there is an explanation here. https://uk.mathworks.com/help/matlab/ref/readtable.html

Upvotes: 2

bushmills
bushmills

Reputation: 673

dlmread and csvread only work for numeric values. try using textread instead: http://de.mathworks.com/help/matlab/ref/textread.html

here you can define your custom format and cast (i.e. str2double) the numeric values, which are in your file as a quoted character string.

Upvotes: 0

Related Questions