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

조회 수: 4 (최근 30일)
Keith
Keith 2012년 6월 7일
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?

답변 (2개)

Geoff
Geoff 2012년 6월 7일
textscan(currentLine, '%s%s%c%d%d%d%d%f%f')

per isakson
per isakson 2012년 6월 7일
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

카테고리

Help CenterFile Exchange에서 Text Files에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by