plot 3D fun in x, y and z
조회 수: 3 (최근 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!