What is the best way to turn a time vector into something plottable when you have large quantities of data?
1 view (last 30 days)
Show older comments
What I need: I need to sequentially plot a calculated value vs. time. and have the x-axis be recognized as a date.
The question: What is the best way to turn a time vector into something plottable?
The problem: I have over 5 million data points. This current code took 1.5 hours to get through %15 of the data. And I will need use this code with additional (possibly more) data at a later time.
What I have: The date in 6 columns [Year, Month, Day, Hour, Minute, Second] The array type is a double. I have over 5 million data points.
Just datenum() allows me to plot it correctly but the axis is unrecognizable as a date.
My current code:
for i= 1:length(Data)
% Other operations
if p1~=0 && p2~=0 % Unrelated to date.
% Other operations
date= datenum([Data(i,1),Data(i,2),Data(i,3),Data(i,4),Data(i,5),Data(i,6)]);
t(i,1) = datetime(date,'ConvertFrom','datenum'); % in 1.5 Hours got through %15 of the data...
end
end
Is there a more efficient way to turn the data into a datetime for plotting? OR is there a way that datenum() can be plotted to show the dates?
Thank you for any and all advice!
3 Comments
dpb
on 16 Jun 2021
That is,
ix=((p1~=0) & (p2~=0)); % NB: if are logical already, then can do away w/ explicit condition
t=datetime(Date(ix));
% Other operations
...
Accepted Answer
Walter Roberson
on 14 Jun 2021
filter the entire data by p1 and p2 giving you 6 columns. pass the 6 to datetime, and it will do a mass conversion. You do not need to use datenum.
2 Comments
dpb
on 16 Jun 2021
Edited: dpb
on 16 Jun 2021
There's no need for the loop or temporary variable --
t= datetime(Data(ix,1:6));
MATLAB is MATrix LABoratory, after all -- vector addressing works in all dimensions, not just the first. :)
Of course, if you have reason for the full datetime array for other purposes, then
tdt= datetime(Data(:,1:6));
and then select the subset along with whatever other data need for analysis with the logical addressing vector.
More Answers (0)
See Also
Categories
Find more on Time Series Objects 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!