Q:

4D visualization in Matlab (Surface and Mesh)

I have four variables, x,y,z,t. I would like to show (x,y,z) in form of a surface such that the color of the surface is determined by t. I want to assign "t" to color bar. Now, color bar is corresponding to z, I want to have it corresponding to "t" my 4th variable.
Thank you for any help

A:

That's very easy: just use
surf(x, y, z, t)

From the documentation,

surf(X,Y,Z,C) uses C to define color. MATLAB® performs a linear transformation on this data to obtain colors from the current colormap.

Here's an example:
x = linspace(0,pi,50);
y = linspace(0,pi/2,50);
z = bsxfun(@times, sin(x), sin(y.')); %'
t = bsxfun(@minus, x, y.'); %'// example data;
surf(x,y,z,t); %// draw surface
colorbar %// show colorbar

