Borrar filtros
Borrar filtros

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

2 visualizaciones (últimos 30 días)
maruljay
maruljay el 19 de Jul. de 2021
Comentada: Peter Perkins el 27 de Jul. de 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).

Respuesta aceptada

Scott MacKenzie
Scott MacKenzie el 19 de Jul. de 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 comentarios
maruljay
maruljay el 20 de Jul. de 2021
Thank you so much. Worked like a charm!
Peter Perkins
Peter Perkins el 27 de Jul. de 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.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Line Plots en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by