MATLAB Answers

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

조회 수: 7(최근 30일)
maruljay 2021년 7월 19일
댓글: Peter Perkins 2021년 7월 27일
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).

채택된 답변

Scott MacKenzie
Scott MacKenzie 2021년 7월 19일
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';
for i=1:nRow
idx1 = n(i,1);
idx2 = n(i,2);
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);
  댓글 수: 2
Peter Perkins
Peter Perkins 2021년 7월 27일
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.

댓글을 달려면 로그인하십시오.

추가 답변(0개)

Community Treasure Hunt

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

Start Hunting!

Translated by