Given an array for x axis 'start' indicies and a second array for x axis 'stop' indicies, how can I create shaded patches for the area between each start and stop index?
I tried to combine the two arrays into one matrix and combine with matching min,max y values but it doesnt seem to work well...
Example:
x_start = [43 123 238 374];
x_stop = [57 135 251 394];
% min and max values of the signal
ymin = -20;
ymax = 20;
I would like to create something like this python example I found:

댓글 수: 2

Ameer Hamza
Ameer Hamza 2020년 3월 16일
Can you give a small example of both indices and what is your required output?
barbH
barbH 2020년 3월 16일
Hi, I edited my question. I hope it makes things clearer..

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

 채택된 답변

Adam Danz
Adam Danz 2020년 3월 16일

1 개 추천

Here's a demo using the rectangel function.
% Create x and y values.
y = rand(1,100);
x = linspace(0,10,100); % or x = 1:numel(y)
plot(x,y)
ylim([-1 2])
% Specify start, stop index values (positive integers)
startStopIdx = [ % [start, stop]
10 25;
40 50;
80 92];
% Convert the index values to rectangle coordinates
yl = ylim();
ylim(yl)
startStopX = x(startStopIdx);
width = startStopX(:,2)-startStopX(:,1);
hold on
arrayfun(@(i)rectangle('Position', [startStopX(i,1),yl(1),width(i),range(yl)], ...
'EdgeColor', 'none', 'FaceColor', [0 1 0 .2]), 1:size(startStopX,1))

댓글 수: 2

barbH
barbH 2020년 3월 16일
Perfect! Thanks!
Adam Danz
Adam Danz 2020년 3월 16일
편집: Adam Danz 2020년 3월 16일
Glad I could help.

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Logical에 대해 자세히 알아보기

질문:

2020년 3월 16일

편집:

2020년 3월 16일

Community Treasure Hunt

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

Start Hunting!

Translated by