Importing date & time data from a txt file in Matlab
I have a txt file from which I want to load date & time data. UI import wizard ignores date & time string and loads only numeric data, which is also present in the file.
How can I write a script that would load this date & time data as a vector of multiple values (I mean, 1st date, 2nd date and so on). I know how to manipulate this string with datestr & datenum, my problem lies within loading data.
The file looks like this:
{headerlines}
15/11/08-12:17:00 423.85 开发者_如何学Go 234.54 672.42
15/11/08-12:17:10 456.54 245.98 723.41
15/11/08-12:17:20 478.65 320.67 952.73
I have a problem only with loading this date&time string. I can manage numeric data.
You may have a look at Reading Data in a Formatted Pattern.
While not taking care of your header, a solution could look like this:
fid = fopen('data.txt');
dateItem = [];
values = [];
while ~feof(fid)
[dateItem]= [dateItem ; fscanf(fid,'%s',1)];
[values]= [values ;fscanf(fid,'%f %f %f',3)'];
end
fclose(fid);
精彩评论