I have an issue with isosurface plotting incorrectly. could i get help?

3 views (last 30 days)
im trying to have a go at a 3D field piecewise functions, which will come in handy later for my project, but ive run into an issue and it appears to be plotting very incorrectly.
i was trying out an basic plot below where the plot would be linearly, z=X, until a sphere of radius >=4 could be formed:
clear all
% define an array of values for x y and z
X = 0:00.1:3;
Y = 0:00.1:3;
Z = 0:00.1:3;
[x,y,z]=meshgrid(X,Y,Z);
for i=1:length(X); j=1:length(Y); k=1:length(Z);
if X(i).^2 + Y(j).^2 + Z(k).^2>=4
v(i,j,k)=x(i,j,k).^2 + y(i,j,k).^2 + z(i,j,k).^2;
else
v(i,j,k)=x(i,j,k);
end
end
isosurface(X,Y,Z,v,1,'red'); hold on
isosurface(X,Y,Z,v,4,'blue');
isosurface(X,Y,Z,v,9,'green');
axis([0 3 0 3 0 3]);
xlabel('x')
ylabel('y')
zlabel('z')
grid on
box on
what i would expect is isopleths along any values of x=1 and 2 that would then be truncated by the quarter hemispherical shells of radius>=4, but instead you get the below:
where the isopleths extend the shells into regions where they shouldnt exist, as with the z=x region
thanks for your help

Answers (0)

Community Treasure Hunt

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

Start Hunting!