How do you load a .csv file, skip lines within it, and plot the values?

조회 수: 4 (최근 30일)
Hi. I seem to have problems loading a .csv file (see attached):
Blah
@Blah
2Blah
Blah
f Blah
fa Blah
Blahasd
Blahasda
vasf Blah
as Blah
asdas Blah
Date Time Ch1:
07/25/2012 42:46.0 96.385
07/25/2012 42:46.0 -177.608
07/25/2012 42:46.0 155.481
07/25/2012 42:46.0 64.15
%Here is my code:
fid = fopen('PULL1.CSV');
% I need to skip the 16 lines. header = textscan(fid, '%s',3,'delimiter', ',',... 'headerLines',16);
data = textscan(fid, '%s %s %s' ,'delimiter', ',');
The problem is that it only recognizes the parameters as strings. Date should be a string. Time should be a floating number. The Ch1 column is a set of values that I want to plot vs. time.
fclose(fid);
  댓글 수: 1
T
T 2012년 9월 21일
Also bare in mind that under column Ch1: the time 42:46.0 represents 5:42:46 PM but I am not sure why Excel automatically displays it as shown in the first post.

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

채택된 답변

Walter Roberson
Walter Roberson 2012년 9월 21일
data_to_plot = str2double(data{3});
  댓글 수: 15
T
T 2012년 9월 24일
편집: T 2012년 9월 24일
My x-axis shows the value 7.3487 x10^5 repeatedly. What is the significance of using datenum if what I want is to show the time as it is in the Excel sheet?
Walter Roberson
Walter Roberson 2012년 9월 25일
Use datetick(). You will want to be selective about which time fields you display, as otherwise the tick labels will run into each other.

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

추가 답변 (1개)

per isakson
per isakson 2012년 9월 21일
편집: per isakson 2012년 9월 21일
Try
data = textscan( fid, '%s%s%f', 'Headerlines', 16 );
Delimiter is obviously one or many "space" or tab. Default handles that.

카테고리

Help CenterFile Exchange에서 Dates and Time에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by