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

1 visualización (últimos 30 días)
Doug G
Doug G el 13 de Jul. de 2017
Comentada: Doug G el 13 de Jul. de 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.

Respuesta aceptada

Walter Roberson
Walter Roberson el 13 de Jul. de 2017
Editada: Walter Roberson el 13 de Jul. de 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 comentario
Doug G
Doug G el 13 de Jul. de 2017
Thank you! I knew it was something simple like that. And thanks for the additional tips. Cheers

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Logical en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by