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

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

A=fopen('slip.csv')

0 Comments

Lisa Justin

Tags

Products

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

4 Comments

Walter Roberson on 15 Oct 2012

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

Lisa Justin on 18 Oct 2012

thanks

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

dir=('C:\Lisajustin\Vib')

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

Walter Roberson
Answer by Sachin on 16 Oct 2012

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

http://www.mathworks.in/help/matlab/ref/csvread.html

Hope it helps!!!

0 Comments

Sachin

Contact us