Storing data from .dat file into array

3 views (last 30 days)
Michael Dillon
Michael Dillon on 1 Nov 2015
Commented: Star Strider on 2 Nov 2015
I want to take the data from a .dat file and store it into an array.
I have a .dat file formatted as such:
" 1000
this is the dataset for the FFT lab
0.000000,4.004024
1.000000,3.051631
2.000000,-3.694841
...etc...
999.000000,4.058688"
My current code is
fileID = fopen(filename);
fileData = textscan(fileID, '%f %f', 'HeaderLines', 2, 'CollectOutput', 1);
Data = cell2mat(fileData);
I'm trying to skip the two header lines and store the data into 'Data,' but it ends up being a 1x2 double with '0' and 'NaN.'
Any help would be greatly appreciated.

Answers (1)

Walter Roberson
Walter Roberson on 2 Nov 2015
Remember to specify 'Delimiter', ','

Categories

Find more on Cell Arrays in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!