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
0 个评论
采纳的回答
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
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
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')
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Annotations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!