3

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

Luis Mendo
  • 110,752
  • 13
  • 76
  • 147
Emily
  • 45
  • 2
  • 8

1 Answers1

5

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

enter image description here

Luis Mendo
  • 110,752
  • 13
  • 76
  • 147