How to plot lines as separated segments?

13 ビュー (過去 30 日間)
Serbring
Serbring 2019 年 9 月 1 日
コメント済み: Serbring 2019 年 9 月 1 日
Hi all,
I have a signal and a need to highlight the portion of the signal which meets a specific condition. I have found two ways to accomplish it, plotting line or plotting markers. With line, I have the problem that joint segments (the horizontal segments in the plotted figure below) are created and this may seem that this segments are part of the dataset. On the other hand, with markers is graphically bad-looking, especially when there are abrupt changes in the signal. How can I make the plot on bottom with lines rather than markers?
Thank you
t=[0:0.01:10];
a=sin(2*pi*t);
figure
subplot(2,1,1)
plot(t,a)
hold on
plot(t(a>0.9),a(a>0.9))
title('with line')
subplot(2,1,2)
plot(t,a)
hold on
plot(t(a>0.9),a(a>0.9),'.')
title('with marker')
untitled.jpg

採用された回答

Walter Roberson
Walter Roberson 2019 年 9 月 1 日
t2 = t;
a2 = a;
mask = a<=0.9;
t2(mask) =nan;
a2(mask) =nan;
plot(t2, a2);
  2 件のコメント
Walter Roberson
Walter Roberson 2019 年 9 月 1 日
This can be simplified to
a2 = a;
a2(a2 <= 0.9) = nan;
plot(t, a2)
Serbring
Serbring 2019 年 9 月 1 日
Much simpler than I could think!
Thanks!

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

その他の回答 (0 件)

カテゴリ

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

タグ

製品


リリース

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by