how to omit zero values while plotting the graph

Risposte (1)

dpb
dpb il 6 Apr 2018
Modificato: dpb il 6 Apr 2018
A)
yplot=y; % make a copy of the data specifically for plotting
yplot(yplot==0)=nan; % replace 0 elements with NaN
plot(x,yplot)
will return broken lines between locations which contain zero in yplot
B)
isNZ=(~y==0); % addressing logical array of nonzero elements
plot(x(isNZ),y(isNZ)) % plot only the subset
will be solid line just without those points that were zero

1 Commento

Many thanks. I was struggling with something like this but this code helped me too much

Accedi per commentare.

Commentato:

il 5 Ago 2021

Community Treasure Hunt

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

Start Hunting!

Translated by