How to highlight a portion of time series on a plot?

14 views (last 30 days)
I have a 64 x 3600 matrix containing time series.
I have another matrix (64 x 2) that contain indices of time series that needs to be highlighted. The first row of this matrix is [1223, 1345]. Here 1223 is the starting index and 1345 is the ending index.
I want to plot all the 64 time series in which the length of time series corresponding to these indices are highlited (as shown in example below).

Accepted Answer

Scott MacKenzie
Scott MacKenzie on 19 Jul 2021
Here's what I put together. I'm assuming you want 64 separate plots.
% test data (timeseries)
nRow = 64; % adjust as per your data
nCol = 36; % adjust as per your data
ts = timeseries(rand(nRow,nCol));
% test data (indices)
n = randi(nCol,2,nRow);
n = sort(n, 'ascend')';
f = figure;
f.Color = 'w';
f.WindowState = 'maximize';
tiledlayout('flow');
for i=1:nRow
idx1 = n(i,1);
idx2 = n(i,2);
nexttile;
plot(1:idx1,ts.Data(i,1:idx1),'k','linewidth', 1.5);
hold on;
plot(idx1:idx2,ts.Data(i,idx1:idx2),'r', 'linewidth',1.5);
plot(idx2:length(ts.Data(i,:)),ts.Data(i,idx2:end),'k','linewidth',1.5);
end
  2 Comments
Peter Perkins
Peter Perkins on 27 Jul 2021
It sounds like maruljay had a numeric matrix, each column of which is a "time series". Scott, you've shown using a time series object. That will work, but I'd recommend using a timetable, maybe with 64 variables, maybe with one variable that itself has 64 columns. Essentially the same code, though.

Sign in to comment.

More Answers (0)

Categories

Find more on Line Plots 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!