Slice NaNs showing strange behaviour

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.
I've looked through Primitive but there's no obvious answer to the issue.
Cheers J

댓글 수: 6

Stephen23
Stephen23 2014년 12월 3일
편집: Stephen23 2014년 12월 3일
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
John Atkinson 2014년 12월 3일
편집: John Atkinson 2014년 12월 3일
Hi Stephen,
The problem is that when plotting the data with NaNs, slice removes the end of some of the transects (bottom panel in uploaded image, circled), yet when the same data is plotted with zeros the data is obviously there (top panel).
I've manually checked the datasets and the only difference between them (and the code that is run) is that on the top "bad" values are 0, in the bottom "bad" values are nan. Yet data in the red circle is not displayed.
Cheers, J
Stephen23
Stephen23 2014년 12월 3일
Is this the only part of the data containing NaN's, or are they present throughout the data set?
John Atkinson
John Atkinson 2014년 12월 3일
They're present throughout the dataset and don't show any issues. The data not presented in the red circle is not nans though. Hence why it's presented in the top panel.
Stephen23
Stephen23 2014년 12월 3일
편집: Stephen23 2014년 12월 3일
Can you please edit your question to upload a .mat file of the data array, I would like to give this a try myself.
John Atkinson
John Atkinson 2014년 12월 3일
Uploaded. Also extra line added to code to put in same perspective.

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

질문:

2014년 12월 3일

편집:

2014년 12월 3일

Community Treasure Hunt

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

Start Hunting!

Translated by