MATLAB Answers

How can i read a csv file

Asked by Lisa Justin on 15 Oct 2012

How can i read a csv file. i used fopen but it gives a value of -1





No products are associated with this question.

2 Answers

Answer by Walter Roberson
on 15 Oct 2012
 Accepted answer

csv files are text files, usually written in ASCII or ISO-8896-1 (which is compatible with ASCII).


Walter Roberson
on 15 Oct 2012

fopen() it, fgetl() to read a line. fclose() after you are done.

Lisa Justin on 18 Oct 2012

Hi Walter, i also want to creat a file list of the large csv data i have. when i write dir *.csv i get all data displayed but when i try to write a script say


Listdir=sprintf('%d%d',dir, '\*.csv');

i get error message ??? Error using ==> sprintf Function is not defined for 'struct' inputs.

what could be the problem

Answer by PG
on 16 Oct 2012

You can use 'csvread' function. Refer link below for further details:

Hope it helps!!!


Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi test

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

MATLAB Academy

New to MATLAB?

Learn MATLAB today!