Colour of plot...not based on z coordinate, but on other variable.

2 次查看(过去 30 天)
Hello
I plotted an hyperbolic parabolid surface in Matlab. The colour of the plot is based on the z-coordinate of the surface. But, now I want to visualise the result of an other function (like: f= x+y+2) on the the surface. So the colour of the surface should be based on the result of function f and not on the z-coordinate. Can somebody explain clearly how to do this? Is it a 4dplot?...and/or how this exactly works?
Thanks in advance!
k = 1
x = linspace(-3,3);
y = linspace(-3,3);
[x,y] = meshgrid(x,y);
z = k*x.*y;
mesh(x,y,z)

回答(2 个)

Jonathan Epperl
Jonathan Epperl 2012-11-30
'CDataSource' is the property you need. In your case:
f = x.^2+y.^2; % The "other" function
m = mesh(x,y,z) % m now contains a handle to the mesh
set(m,'CDataSource','f') % 'CDataSource' is a variable name as a string
refreshdata % That's necessary so Matlab reevaluates the CDataSource

Dirk
Dirk 2012-11-30
hmm..I dont get it.
When i add your code, nothing in the plot changes:
i.e. when f = x, the points with te same x coordinate should be plotted in the same color.
When f = cte, the whole surface should be plotted in the same color.
  1 个评论
Jonathan Epperl
Jonathan Epperl 2012-12-1
Did you copy&paste my code? It works fine for me. Run your code that you posted in the original post, then run my code, the color should change. Did you mess with the colormap already? Try colormap cool or something like that, that should change the colors.
Every time you change the value of 'CDataSource' (whether you assign a different variable or change the value of the variable you designated CDataSource) you will have to call refreshdata.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Surface and Mesh Plots 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by