How to use function "scatter3(y)" to show the image of a 3D matrix?

5 ビュー (過去 30 日間)
Jianwei Guo
Jianwei Guo 2012 年 3 月 8 日
I want to use Matlab to show the image of a 3D matrix made up of 1 and 0. For example, a 3*3*3 matrix named testy, and
testy(:,:,1)=[1,1,0;0,0,0;0,0,0];
testy(:,:,2)=[0,0,0;1,1,0;0,0,0];
testy(:,:,3)=[0,0,0;0,0,0;1,1,0];
I know that function "spy(y)" is used to show the image of 2D matrx, and I find it's easy to use. But I didn't get much from the help document about scatter3, especially, I'm confused about the example of sphere and the format of X,Y,Z.
Any suggestion will be helpful,and thank you very much.

採用された回答

Jacob Halbrooks
Jacob Halbrooks 2012 年 3 月 8 日
SCATTER3 takes its data as vectors and interprets them as the locations to place circles. In the help example for SCATTER3, the X,Y, and Z matrices returned by SPHERE are indexed with : to convert them to vectors. For your example, this might looks like:
testy(:,:,1)=[1,1,0;0,0,0;0,0,0];
testy(:,:,2)=[0,0,0;1,1,0;0,0,0];
testy(:,:,3)=[0,0,0;0,0,0;1,1,0];
Xmatrix = testy(:,:,1);
Ymatrix = testy(:,:,2);
Zmatrix = testy(:,:,3);
scatter3(Xmatrix(:), Ymatrix(:), Zmatrix(:));
However, based on your mention of SPY, I suspect that you are not interested in the plot above but instead in seeing the (x,y,z) locations of each 1 plotted. If this is the case, it might be helpful to use IND2SUB with FIND to get the coordinates of each 1 and then plot this with SCATTER3:
[rowInd,colInd,zInd]=ind2sub(size(testy),find(testy));
scatter3(colInd, rowInd, zInd);
The resultant scatter plot is similar to stacking SPY plots of each matrix sheet.
  1 件のコメント
Jianwei Guo
Jianwei Guo 2012 年 3 月 9 日
That's just what I mean by mention of SPY. And thank you very much!
By the way, sometimes it's slow to show the image in figure when the size of data is large. Do you know how to improve that or is that related to video adapter of my PC? Mine is NVIDIA GeForce 9500GT and CPU is 4-core.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeScatter Plots についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by