time analysis of data
1 view (last 30 days)
I have following text file
id, start_time, stop_time, value
1 XXX1 YYY1 13
9 XXX2 YYY2 65
7 XXX3 YYY3 82
1 XXX4 YYY4 5
1 XXX5 YYY5 6
the id is related to variable name, the times are Year-Month-Day-Hour-Minute-Second-Milisecond (all concatinated, without dashes or any other characters)
The times of each row can be partially (or fully or no) overlapping.
I'd like to perform some analysis and plot the data (lets say id 1 and 7 on same plot)
It can that id 7 will appear only once (with first time of data arrival till end of the data colleciton) while id 1 will appear 100 times (with first time of data arrival which can be differnt from id 7 till end of the data colleciton).
How would you recomment to handle the data in Matlab (read it, store it and plot it so that the access would be user friendly).
Walter Roberson on 2 Nov 2022
I might suggest using detectImportOptions() on the file. Then use setvartype() to set the second and third columns to DateTime, and set the InputFormat for those variables to 'uuuuMMddHHmmssSSS' or as appropriate (year, month, day, 24 hour hour, minutes, seconds, fractions of a second.) Then readtable() using the altered options.
You can do subset selection such as
mask7 = T.id == 7;
subset7 = T(mask7, :);
t7 = [subset7.start_time, subset7.end_time];
t7(:,end+1) = nan;
v7 = repelem(subset7.value, 1, 2);
v7(:,end+1) = nan;
t7 = reshape(t7.', , 1);
v7 = reshape(v7.', , 1);
The purpose of this code would to draw a horizontal line at "value" from the start time for the value to the end time of the value. The nans are there to force it to break the drawing after each segment.