Suppose we have a 3D array r(x,y,z) filled with values 1 and 2. 1. How to visualise it into a 3D model? 2. How to visualise only "2" values, i.e. make "1" invisible? Thank you!

 채택된 답변

Massimo Zanetti
Massimo Zanetti 2016년 9월 26일
편집: Massimo Zanetti 2016년 9월 26일

3 개 추천

Ok, so try this one. It includes a fast way to generate a random array with only 1 or 2 entries.
%generate a 3d-matrix of size 10x5x5 with values 1,2.
R = randi(2,10,5,5);
%define coordinate grid
x = 1:10; y = 1:5; z = 1:5;
[X,Y,Z] = meshgrid(x,y,z);
%detect points with label=1
I1 = R==1;
%plot points with label=1
scatter3(X(I1),Y(I1),Z(I1),'filled');

추가 답변 (1개)

Massimo Zanetti
Massimo Zanetti 2016년 9월 26일
편집: Massimo Zanetti 2016년 9월 26일

0 개 추천

Try this out. Given a set of 10 points (3dim) and a set of labels (1,2) it returns the plot of the points according to the labels.
XYZ = rand(10,3);
R = [1,1,2,1,2,2,2,1,2,1];
R1 = (R==1);
R2 = (R==2);
figure;
scatter3(XYZ(R1,1),XYZ(R1,2),XYZ(R1,3),'r','filled');
hold on;
scatter3(XYZ(R2,1),XYZ(R2,2),XYZ(R2,3),'b','filled');
hold off;
You may also want to map colors of the colormap directly to labels, in automated way.
figure;
scatter3(XYZ(:,1),XYZ(:,2),XYZ(:,3),30,R,'filled');

댓글 수: 8

Vadim Tambovtsev
Vadim Tambovtsev 2016년 9월 26일
편집: Vadim Tambovtsev 2016년 9월 26일
r=[1 2 1; 1 1 1; 2 2 2]
R1=(r==1);
R2=(r==2);
figure;
scatter3(r(R1,1),r(R1,2),r(R1,3));
If I test your code using this trivial 3D matrix, I get an error "
Index exceeds matrix dimensions.
Error in test1 (line 6)
scatter3(r(R1,1),r(R1,2),r(R1,3)); "
Can you please correct my script?
Massimo Zanetti
Massimo Zanetti 2016년 9월 26일
Is your "r" the matrix of coordinates or labels? They are different.
Vadim Tambovtsev
Vadim Tambovtsev 2016년 9월 26일
r is the set of values
Massimo Zanetti
Massimo Zanetti 2016년 9월 26일
And where you stored the 3d point coordinates? Why is your "r" a matrix instead of a vector?
Vadim Tambovtsev
Vadim Tambovtsev 2016년 9월 26일
Initially I have a big grid 100x50x50, filled with values 1 and 2. r(x,y,z). r is the coordinates, not values. But each r(x,y,z) can be either 1 or 2.
Massimo Zanetti
Massimo Zanetti 2016년 9월 26일
So for each 3d point, you have 3 labels??
Massimo Zanetti
Massimo Zanetti 2016년 9월 26일
Can you give me an examplt of an input yuo have to display?
Vadim Tambovtsev
Vadim Tambovtsev 2016년 9월 26일
Example

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Discrete Data Plots에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by