plot and ignore certain values

18 ビュー (過去 30 日間)
David C
David C 2012 年 4 月 24 日
コメント済み: Samuel Bartlett 2018 年 5 月 14 日
I have a vector I need to plot that contains numerics gathered from a data acquisition board collecting at 1 hz (1 point / sec).
any time signal is lost, a placeholder "-1" value is used in that cell and I need to plot this vector but not have it plot the "-1"s
is the plot function capable of such a task? or do I have to remove all the "-1"s first?
  1 件のコメント
Nathaniel Menefee
Nathaniel Menefee 2017 年 3 月 10 日
So i want to do that same thing but i want to do it with 2 different plots. is there any way to do this.

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

採用された回答

Wayne King
Wayne King 2012 年 4 月 25 日
You can set those values to NaN
x(x == -1) = NaN;
plot(x)
They will show up as gaps in your plot.
  2 件のコメント
David C
David C 2012 年 4 月 25 日
bingo, logical indexing saves the day! Thanks Wayne!
Samuel Bartlett
Samuel Bartlett 2018 年 5 月 14 日
THANK YOU SO MUCH!!! This saved my life!

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

その他の回答 (1 件)

Wayne King
Wayne King 2012 年 4 月 24 日
You can just plot x for x~= -1 or did you mean that the character array "-1" is entered? Not sure what you mean by the " ".
x = randi([-1 4],20,1);
plot(x(x~= -1))
  1 件のコメント
David C
David C 2012 年 4 月 24 日
almost did the trick
your code stitched the gaps together for the areas where -1 was present, but I would like for it to leave the gaps present!
Thank you!

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

カテゴリ

Help Center および File Exchange2-D and 3-D Plots についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by