フィルターのクリア

How to give different colour for those indices which is zero in matlab plot

2 ビュー (過去 30 日間)
POKA
POKA 2017 年 7 月 29 日
コメント済み: POKA 2017 年 7 月 30 日
Hi All,
I am plotting numerical sensor data from huge file. I got my plot. But I want to show red colour to those points which is zero in the plot. I mean these data are wrong data and I want to give them different colur in the plot.
I tried with
idx=find(not(input5(:,1)));
But it will plot total zeros in the plot.How Can I rectify it. Thanks

採用された回答

Image Analyst
Image Analyst 2017 年 7 月 30 日
POKA, try this:
y = rand(1, 50) - 0.3;
x = 1 : length(y);
% clip some points to zero
y(y < 0) = 0;
% Find indexes above 0
aboveZero = y > 0;
% Plot all data.
plot(x, y, 'b*-', 'LineWidth', 2);
hold on;
grid on;
% Plot all data zero as red spots.
plot(x(~aboveZero), y(~aboveZero), 'r.', 'MarkerSize', 30);
xlabel('x', 'FontSize', 30);
ylabel('y', 'FontSize', 30);
title('Bad Data in Red', 'FontSize', 30);
  7 件のコメント
Image Analyst
Image Analyst 2017 年 7 月 30 日
Ignore the first few lines where I had to create my own data because you initially forgot to attach yours:
y = rand(1, 50) - 0.3;
x = 1 : length(y);
% clip some points to zero
y(y < 0) = 0;
I had to have some data for the demo right? And I didn't have your data so I made up some. Since you already have the y data, you can just pick up with the line of code after those.
POKA
POKA 2017 年 7 月 30 日
Thanks understood .

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

その他の回答 (1 件)

David Goodmanson
David Goodmanson 2017 年 7 月 30 日
編集済み: David Goodmanson 2017 年 7 月 30 日
Hi POKA,
something like this?
x = 0:.01:50;
y = sin(x);
ind = abs(y)<.005 % or whatever tolerance is appropriate to find the zeros;
% sometimes y == 0 will not work
plot(x,y,x(ind),y(ind),'.r')

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by