plot 3D fun in x, y and z
8 次查看(过去 30 天)
显示 更早的评论
i want to draw a function f varied in x, y and z such that f = xyz using matlab 2014a
0 个评论
回答(2 个)
John BG
2017-3-28
Hi hend
since your function takes in all 3 coordinates, the only way to 'see' or plot the function is slicing the volume comprised by the domain used.
For such purpose the command slice comes really handy, have a look:
N=10
range=[-N:1:N]
[x,y,z] = meshgrid(range,range,range);
v = x.*y.*z;
figure
colormap hsv
for k = range
hsp = surf(linspace(-N,N,numel(range)),linspace(-N,N,numel(range)), zeros(numel(range)) + k);
rotate(hsp,[2,-2,2],15)
xd = hsp.XData;yd = hsp.YData;zd = hsp.ZData;
delete(hsp)
slice(x,y,z,v,[-N,N],2*N,-2*N) % static volume boundaries
hold on
h1=slice(x,y,z,v,xd,yd,zd) % this is the slicing plane
hold off
view(-5,10)
axis([-10 10 -10 10 -10 10])
drawnow
colorbar
end
note the handle h1 to pull the values on the slice plane, that may be useful to extract the slicing plane points with
Xslice=h1.XData
Yslice=h1.YData
Zslice=h1.ZData
the colour bar is also useful to visualise the actual value of the function.
if you find these lines useful would you please be so kind consider marking my answer as Accepted Answer?
To any other reader, if you find this answer of any help would you please click on the thumbs-up vote link,
thanks in advance for time and attention
John BG
0 个评论
KSSV
2017-3-28
N = 10 ;
x = linspace(0,1,N) ;
y = linspace(0,1,N) ;
z = linspace(0,1,N) ;
[X,Y,Z] = meshgrid(x,y,z) ;
f = X.*Y.*Z ;
figure(1)
hold on
for i = 1:N
surf(X(:,:,i),Y(:,:,i),Z(:,:,i),f(:,:,i))
end
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Orange 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!