4

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

2
  • It looks like your data contains a quoted character string in row 1 field 1, not a number. Commented Sep 5, 2016 at 1:35
  • Yes that is exactly the problem. Thanks! Commented Sep 6, 2016 at 16:38

2 Answers 2

2

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

Sign up to request clarification or add additional context in comments.

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.