How to give different colour for those indices which is zero in matlab plot
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponse acceptée
Image Analyst
le 30 Juil 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 commentaires
Image Analyst
le 30 Juil 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.
Plus de réponses (1)
David Goodmanson
le 30 Juil 2017
Modifié(e) : David Goodmanson
le 30 Juil 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 commentaires
Voir également
Catégories
En savoir plus sur Annotations dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!