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).


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


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!!!


Join the 15-year community celebration.

Play games and win prizes!

Learn more
Discover MakerZone

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

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!