MATLAB Answers

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

1 view (last 30 days)
Keith
Keith on 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 Comments

Sign in to comment.

Answers (2)


per isakson
per isakson on 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 Comments

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!