MATLAB Answers

0

Entering data into MATLAB from a csv file containing both data and letters

Keith 님이 질문을 제출함. 7 Jun 2012
I'm trying to load into MATLAB the following using textscan:
DATE PG Index Wind Speed (knots) Direction Marrowbone (Hourly Wind Speed) Marrowbone (Hourly Wind Direction) Pius (Hourly Wind Speed) Pius (Hourly Wind Direction)
27/11/2010 00:00 E 9 310 0 0 0 0
27/11/2010 01:00 D 8 310 0 0 1.4974 127.62
27/11/2010 02:00 D 9 310 0 0 2.4882 255.84
27/11/2010 03:00 D 9 310 0 0 2.0637 271.87
27/11/2010 04:00 D 11 310 0 0 2.5605 294.59
I always have problems loading this type of data!
I'd ultimately like to count the number of 'D' values over 24 hours and if it's less than a specific value to delet the day. Any suggestions?

  댓글 수: 0

로그인 to comment.

답변 수: 2

Geoff 님의 답변 7 Jun 2012

textscan(currentLine, '%s%s%c%d%d%d%d%f%f')

  댓글 수: 0

로그인 to comment.


per isakson 님의 답변 7 Jun 2012

I copy&paste your data to ascii_with_colhead_date_time.txt and tried importdata
>> A = importdata( 'ascii_with_colhead_date_time.txt')
A =
data: [5x6 double]
textdata: {6x8 cell}
>> A.data
ans =
9.0000 310.0000 0 0 0 0
8.0000 310.0000 0 0 1.4974 127.6200
9.0000 310.0000 0 0 2.4882 255.8400
9.0000 310.0000 0 0 2.0637 271.8700
11.0000 310.0000 0 0 2.5605 294.5900
>> A.textdata
ans =
Columns 1 through 5
'DATE' 'PG Index' 'Wind Speed (knots)'
'27/11/2010 00:00' 'E' ''
'27/11/2010 01:00' 'D' ''
'27/11/2010 02:00' 'D' ''
'27/11/2010 03:00' 'D' ''
'27/11/2010 04:00' 'D' ''
A.textdata is truncated to avoid wordwrap

  댓글 수: 0

로그인 to comment.



Translated by