how to plot by scatter3 a 3D matrix with its elements being logic variables?

I made a 3D matrix representing a ellipsoid. The elements are logic variables, 1 or NaN. I thought this 3D matrix as Cartesian coordinate and the points on it. I want to plot this by using scatter3. But scatter3 accepts 1D vectors as inputs for position. (Before, I made a 2D matrix representing a ellipsoid and plotted this by using imagesc. This function accepts 2D matrix and don't require position vectors.)
Here is the code.
%making a coordinate
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);
%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;
Now I don't know how to transform the matrix for scatter3

 採用された回答

jonas
jonas 2018 年 9 月 12 日
編集済み: jonas 2018 年 9 月 12 日
You can use your logic data in A to set the color and your X, Y and Z data for coordinates.
scatter3(X(:),Y(:),Z(:),[],A(:))

7 件のコメント

Woo-Seok Lee
Woo-Seok Lee 2018 年 9 月 13 日
Thank you so much!!!
I want to plot another ellipsoid with half radius of the first one.
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;
figure, scatter3(X(:),Y(:),Z(:),[],A(:)), colormap cool, axis equal, axis tight, grid on;
hold on;
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;
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?
jonas
jonas 2018 年 9 月 13 日
That's because the smaller ellipsiod is hidden by the larger one. You can increase transparency of the larger one to see the smaller.
save handles when you plot, i.e.
h1=scatter3(X(:),Y(:),Z(:),[],A(:))
h2=scatter3(X(:),Y(:),Z(:),[],A2(:));
then increase transparency of the larger one
set(h1,'markeredgealpha',0.05)
Woo-Seok Lee
Woo-Seok Lee 2018 年 9 月 13 日
Thank you soooo much!!!
jonas
jonas 2018 年 9 月 13 日
Happy to help!
Valeriy
Valeriy 2018 年 11 月 18 日
I try tor reproduce command set(h1,'markeredgealpha',0.05),
but I have obtained message:
Error using specgraph.scattergroup/set
The name 'markeredgealpha' is not an accessible property for an instance
of class 'scattergroup'.
Help for scattergroup properties don't show presence of "markeredgealpha". How it works?
jonas
jonas 2018 年 11 月 18 日
You probably have to specify that already when plotting, i.e.:
scatter(..., 'markeredgealpha',0.05)

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

質問済み:

2018 年 9 月 12 日

コメント済み:

2018 年 11 月 18 日

Community Treasure Hunt

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

Start Hunting!

Translated by