using textscan with csv - seemly basic but not working at all

1 vue (au cours des 30 derniers jours)
Doug G
Doug G le 13 Juil 2017
Commenté : Doug G le 13 Juil 2017
Hi all,
This is embarrassingly simple but I've had no luck in succeeding in importing my basic csv file using textscan. I've tried several variations of the conversion but nothing is working.
Here's the first few rows of the file:
month date year uavg vavg n mavg davg usd vsd msd dsd
6 1 2006 0.4464 -9.5247 6803 15.64 189.24 9.99 11.88 9.35 65.43
7 1 2006 3.1004 -3.0014 52332 15.3 175.55 12.72 11.54 8.92 89.82
8 1 2006 3.1502 -14.3924 49746 24.72 134.94 17.31 17.34 14.38 65.69
9 1 2006 -4.1448 -8.1912 46222 18.54 182.83 13.84 14.66 12.12 74.05
My attempts have all followed the examples and other codes I've written. There's this one:
fid = fopen('Baja_Border_J1_prep.csv');
data = textscan(fid,'%f32 %f32 %f32 %f32 %f32 %f32 %f32 %f32 %f32 %f32 %f32 %f32', 'Headerlines', 1);
fclose(fid);
And this one:
data = textscan(fid,'%d %d %d %d %d %d %d %d %d %d %d %d', 'Headerlines', 1);
All I get as output is a cell array that is empty but no error messages that something is wrong.
Any guidance here would be great and much appreciated. I'm really perplexed that it's not working!
Thank you.

Réponse acceptée

Walter Roberson
Walter Roberson le 13 Juil 2017
Modifié(e) : Walter Roberson le 13 Juil 2017
You forgot the 'Delimiter', ',' option.
Note: do not use %d format for fields that are floating point numbers. You could safely use %d for the year field.
I seldom use %f32, which would be for reading single precision. It is justified sometimes, but it does tend to lead to longer programs to mix singles and doubles in the proper manner. Unless I am short on memory I usually just use %f
  1 commentaire
Doug G
Doug G le 13 Juil 2017
Thank you! I knew it was something simple like that. And thanks for the additional tips. Cheers

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by