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

4 次查看(过去 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.

请先登录,再进行评论。

更多回答(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 CenterFile Exchange 中查找有关 Annotations 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by