MATLAB: Contour and Scatter in the same figure

contourplotscatter3triplets

Hello all,
I have a problem using the functions "contour" and "scatter3". I hope I can explain it clearly: I have 2 triplets of data: x,y,w and x,y,z. The x and y coordinates are the same for both of them.
I know how to represent a triplet using the function "scatter3". I also know how to make a contour plot of these data (separetely for the w and z coordinates) using the meshgrid and griddata functions.
The problem I have happens when I want to make a contour plot (with the values of w) and a scatter3 plot(with the z values) in the same figure. Actually, I can represent both plots simultaneously. The contour plot is normal, but the scatter3 plot has all the points with the same color, and I wanted it to have different colour depending on the values of its z variable (as usual). This way I could see easier (with the help of the different colours) the values of both variables in one single plot.
Does anyone know how to do it??
Thanks in advance!
P.S. I have tried this in Matlab 7.3 and 7.6 and it does not work in any of them.

Best Answer

contour internally uses integer CData values if colors are not specified, and normally the integers get scaled to the total range of the color map.
If scatter3 is specifically used with the raw zdata values as the colors, then when used in isolation, the raw zdata value range would get scaled to the total range of the color map.
Put these two together and unless the zdata value range happens to be from 1 to the number of contours, the color transform of one or the other is going to be messed up.
I can think of a couple of ways that one might compensate for this, but before going in to them, I would rather that xkudsraw indicate how their code is currently constructed... no point in my detailing a solution if I have guessed wrong about the problem ;-)