Slice NaNs showing strange behaviour
Show older comments
I have a 701 x 5 x 29 3D array (named V), produced from meshgrid and interp2. The data is good, i've checked through each layer and everything is in order (no data missing, monotonically spaced, and nans used for no data), the problem arises when I plot the data in slice, where the use of NaNs cuts the end of the data off (circled, bottom image).
If I replace the NaN's with zeros the data shows up, but then the issue is that the white isn't transparent (see attached). Here's the applicable code (removed axis labels etc)
V(isnan(V)) = 0; %uncomment and full lines are plotted
V_p = permute(V,[3 2 1]);
[XI3d,YI3d,ZI3d] = meshgrid(1:size(V_p,2),YI,XI); % all working
figure
slice(XI3d,YI3d,ZI3d,V_p, 1:5,0,0);
shading flat
set(gca(),'Zdir','reverse');
set(gca(),'xdir','reverse');
xlim([1 5]);
caxis([140 230]);
colormap([1,1,1;jet(64)]);
view(73,66)
So two part question: Is this just another Matlab quirk which you have to work around or is there a simple way to stop it? Is there an easy way to make one color within a color map transparent instead of the whole thing.
Cheers J

6 Comments
What exactly is the problem? The correct and documented behavior is that NaN's are ignored in plotting. Of course if you replace these NaN's with zeros (or some other finite value) then these will be plotted and colored depending on the current colormap .
It is not clear what you expect to happen, you only mention "the problem arises", but do not state what this problem is. Can you please clarify exactly what part of the plot is not to your liking.
It might be related to interpolating data containing NaN's: you might like to check the data that you actually plotting to see how many and where the NaN's are.
John Atkinson
on 3 Dec 2014
Edited: John Atkinson
on 3 Dec 2014
Stephen23
on 3 Dec 2014
Is this the only part of the data containing NaN's, or are they present throughout the data set?
John Atkinson
on 3 Dec 2014
John Atkinson
on 3 Dec 2014
Answers (0)
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!