Effacer les filtres
Effacer les filtres

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

2 vues (au cours des 30 derniers jours)
maruljay
maruljay le 19 Juil 2021
Commenté : Peter Perkins le 27 Juil 2021
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).

Réponse acceptée

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

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Line Plots dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by