MATLAB: How to overlay multiple images using scatter3

ellipsoidoverlayscatter3

I want to plot two ellipsoids.
%making axes
Sx=1; Sy=1; Sz=1; Nx=50; Ny=50; Nz=50; dx= Sx/Nx; dy=Sy/Ny; dz=Sz/Nz;
xa=[0:Nx-1]*dx;
ya=[0:Ny-1]*dy;
za=[0:Nz-1]*dz;
xa=xa-mean(xa);
ya=ya-mean(ya);
za=za-mean(za);
[X,Y,Z]=meshgrid(xa,ya,za);
%bigger ellipsoid
rx=0.5;
ry=0.35;
rz=0.2;
A=zeros(length(xa),length(ya),length(za));
A(((X/rx).^2+(Y/ry).^2+(Z/rz).^2)<=1)=1;
A(((X/rx).^2+(Y/ry).^2+(Z/rz).^2)>1)=NaN;
%plotting by scatter3
figure, scatter3(X(:),Y(:),Z(:),[],A(:)), colormap cool, axis equal, axis tight, grid on;
hold on;
%smaller ellipsoid with half radius
rx=rx/2;
ry=ry/2;
rz=rz/2;
A2=zeros(length(xa),length(ya),length(za));
A2(((X/rx).^2+(Y/ry).^2+(Z/rz).^2)<=1)=0;
A2(((X/rx).^2+(Y/ry).^2+(Z/rz).^2)>1)=NaN;
%plotting smaller one by scatter3
scatter3(X(:),Y(:),Z(:),[],A2(:));
hold off;
But the the latter scatter3 function doesn't make any change. When I only run the code:
scatter3(X(:),Y(:),Z(:),[],A2(:));
then smaller ellipsoid is shown. When the whole code run, only the bigger one is shown. What's the problem?

Best Answer

This is a continuation of this question.
As I just stated in that thread, the reason is due to the smaller ellipsoid being hidden by the larger one. You can increase the transparency of the larger one to see both.
First save the handles when you plot:
h1=scatter3(X(:),Y(:),Z(:),[],A(:))
h2=scatter3(X(:),Y(:),Z(:),[],A2(:));
then increase transparency of the larger one
set(h1,'markeredgealpha',0.05)