process data from csv file

조회 수: 1 (최근 30일)
Yang
Yang 2014년 5월 21일
댓글: Yang 2014년 5월 22일
Hi to all. I am trying to process data from a csv file using matlab. The csv file is like below:
Time, Value
1400660853.068, 614
1400661093.002, 641
1400661332.698, 599
So we have the first line as header and the rest of the first and second columns as data. I am interested in the second column which is the value. I would like to get the column as a matrix(not include the header). How could I do that? I tried to use the textscan command as below:
_clear;
close all;
fid=fopen('C:\Users\yyao\Desktop\Luminance_18.csv');
out=textscan(fid,'%f %d','delimiter',',');
date=out{2}
fclose(fid);_
But then I got date = Empty matrix: 0-by-1
Is there anything wrong with my codes? Thanks so much for helping!

채택된 답변

Romain
Romain 2014년 5월 21일
편집: Romain 2014년 5월 21일
I suggest you to use the function csvread :
clear;
close all;
out = csvread('C:\Users\yyao\Desktop\Luminance_18.csv',1,0); % start to read at the second row and the first column
value = out(:,2)
  댓글 수: 1
Yang
Yang 2014년 5월 22일
Hi,Romain
Thank you so much! It works! It seems that I really have a lot to learn:)

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Data Import and Export에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by