Ignoring certain matrix entries with surf plot
Show older comments
Hi!
I am attempting to plot some data in a matrix using the surf command. Every nonzero elements happens to be padded by zero elements (i.e. the elements
and
are zero for every nonzero
. I'd like to plot a surface of the nonzero elements only, but I have tried a number of things and have not been able to figure out how to exclude the zero elements. For instance, I tried something like
MatrixName(MatrixName==0)=NaN;
Surf(x,y,MatrixName);
but this method ignores all patches contiaining the zero element points and, due to the nature of my matrix, all surface patches are ignored.
Does anyone know how to request that matlab simply ignore zero elements in generating a surface plot?
Sincerely,
Jacob
Accepted Answer
More Answers (1)
darova
on 9 Aug 2021
Don't use '==' equal sign for comparing double numbers
ii = abs(MatrixName-0)<0.1; % precision
MatrixName(ii) = NaN;
1 Comment
Jacob Wilson
on 9 Aug 2021
Categories
Find more on Surface and Mesh Plots 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!