Time Series Objects

8 views (last 30 days)
mathworks2011
mathworks2011 on 21 Jul 2011
Hello.
I say:
fid = fopen(myPath);
M = textscan(fid, '%s %s %s %f %d %f %f %d %d', 'delimiter', ',', 'EmptyValue', NaN);
fclose(fid);
The size of M is 1 x 9.
M{1} is N x 1. N is very large (>> 2 million). This is also the case for other M.
M{1} contains time in the format HH:MM:SS:fff where f is in miliseconds. I know datenum does not support ms.
M{2} contains a string of values A1,B1 or C1.
Other M{} contain floats, int or other strings.
I wish to build a timeseries collection. This allows me to only use the time stamps once and thus saves on space.
I also have many "M" (i.e. tens of thousands).
I would like to write something like the following, which is wrong.
time = cell2mat(M{1});
time = datenum(time, 'HH:MM:SS:fff');
cols = {'a','b','c','d','e','f','g','h','i'};
data = NaN(size(M{1},1), size(cols,2));
data(:,1) = cell2mat(M{2});
data(:,2) = cell2mat(M{3});
data(:,3) = cell2mat(M{4});
data(:,4) = cell2mat(M{5});
data(:,5) = cell2mat(M{6});
data(:,6) = cell2mat(M{7});
data(:,7) = cell2mat(M{8});
data(:,8) = cell2mat(M{9});
for i = 1: size(cols,2)
ts{i} = timeseries(data(:,i), time, 'Name', cols{i});
end
tsc = tscollection(ts);
I have two questions.
1. How to represent the ms in my data? Is there a datenum method that supports ms out there? I think people might suggest that I fractionally increase my seconds timestamp. I dont think this is correct as it would require looping through each value and I have millions of obs in each timeseries and thus its not practical.
2. How to represent my strings in my data? Matlab timeseries objects don't allow the data to be strings. Would the best way to be to map my finite set of strings to a number? If so I then face the same problem as in Qus 1.
Many Thanks!
  1 Comment
mathworks2011
mathworks2011 on 21 Jul 2011
I have partially solved this part 2, by mapping my strings to Ints and using these when generating the file which becomes M. Ie. no need to deal with strings any more.

Sign in to comment.

Answers (0)

Categories

Find more on Dates and Time in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!