Azzera filtri
Azzera filtri

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

2 visualizzazioni (ultimi 30 giorni)
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).

Risposta accettata

Scott MacKenzie
Scott MacKenzie il 19 Lug 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 Commenti
maruljay
maruljay il 20 Lug 2021
Thank you so much. Worked like a charm!
Peter Perkins
Peter Perkins il 27 Lug 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.

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Line Plots in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by