How to give different colour for those indices which is zero in matlab plot
4 views (last 30 days)
Show older comments
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
0 Comments
Accepted Answer
Image Analyst
on 30 Jul 2017
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 Comments
Image Analyst
on 30 Jul 2017
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.
More Answers (1)
David Goodmanson
on 30 Jul 2017
Edited: David Goodmanson
on 30 Jul 2017
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')
0 Comments
See Also
Categories
Find more on Annotations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!