Painting the area of difference between two lines

2 ビュー (過去 30 日間)
Woonsup Choi
Woonsup Choi 2016 年 2 月 11 日
コメント済み: Star Strider 2016 年 2 月 11 日
I have a plot like the image. There are two occasions where the orange line is above the blue line (around 211 and 331 on the x-axis). I would like to paint the area between the two lines for the two occasions to highlight that the blue is below the orange.

採用された回答

Star Strider
Star Strider 2016 年 2 月 11 日
I don’t have your data, so I created my own:
zci = @(v) find(v(:).*circshift(v(:), [-1 0]) <= 0); % Returns Zero-Crossing Indices Of Argument Vector
x = linspace(0, 100, 250); % Independent Variable
y1 = exp(-0.05*x).*sin(2*pi*x/30); % First Dependent Variable
y2 = 0.5*exp(-0.07*x).*sin(2*pi*x/20); % Second Dependent Variable
yd = y1 - y2; % Difference (Use To Detect Zero-Crossings)
xc = zci(yd); % Zero Crossings
idxs = xc(2:2:end-1); % Start Indices Of Overlap
idxe = xc(3:2:end); % End Indices Of Overlap
figure(1)
plot(x, y1)
hold on
plot(x, y2)
for k1 = 1:size(idxs,1)
fill([x(idxs(k1):idxe(k1)) fliplr(x(idxs(k1):idxe(k1)))], [y1(idxs(k1):idxe(k1)) fliplr(y2(idxs(k1):idxe(k1)))], 'g')
end
hold off
grid
You should be able to adapt it to your data with little or no alteration, although you might need to adjust ‘idxs’ and ‘idxe’.
  2 件のコメント
Woonsup Choi
Woonsup Choi 2016 年 2 月 11 日
Thanks again. I had to adjust 'idxs' and 'idxe'.
Star Strider
Star Strider 2016 年 2 月 11 日
My pleasure.
I anticipated you would.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeHistograms についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by