using textscan with csv - seemly basic but not working at all
1 回表示 (過去 30 日間)
古いコメントを表示
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.
0 件のコメント
採用された回答
Walter Roberson
2017 年 7 月 13 日
編集済み: Walter Roberson
2017 年 7 月 13 日
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
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Logical についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!