MATLAB Answers

0

3D plotting help

jiyoung lee さんによって質問されました 2019 年 6 月 15 日
最新アクティビティ dpb
さんによって 編集されました 2019 年 6 月 16 日
dpb
さんの 回答が採用されました
I want to change the dot colour in a 3D graph according to range
For example A(1,1,1) B(2,2,2), C(3,3,3) D(4,4,4) ... (X,Y,Z)
And
X<=1, Y<=1, Z<=1 --> red dot /
1<X<=3, 1<Y<=3, 1<Z<=3 --> green dots /
3<X<=5, 3<Y<=5, 3<Z<=5 --> blue dot
(Please code easy to change the number)
-------------------------------------------------
Here what i've done
-------------------------------------------------
data=[1,1,1 ; 2,2,2 ; 3,3,3; 4,4,4]
x=data(:,1);
y=data(:,2);
z=data(:,3);
figure
scatter3(x,y,z)
I already tried --------- scatter3(x,y,z,50,z,'filled')------- and it changed all dots' colour
And one more, i want to divide the sections and change the colour of each section
Thank you

  0 件のコメント

サインイン to comment.

1 件の回答

dpb
回答者: dpb
2019 年 6 月 16 日
編集済み: dpb
2019 年 6 月 16 日
 採用された回答

Per the documentation for scatter3,
scatter3(X,Y,Z,S,C) draws each circle with the color specified by C.
  • If C is a RGB triplet or character vector or string containing a color name, then all circles are plotted with the specified color.
  • If C is a three column matrix with the number of rows in C equal to the length of X, Y, and Z, then each row of C specifies an RGB color value for the corresponding circle.
  • If C is a vector with length equal to the length of X, Y, and Z, then the values in C are linearly mapped to the colors in the current colormap.
For your case, you want the second option of the three, what you tried was the first.
C=[1 0 0;0 1 0;0 1 0;0 0 1];
hSc=scatter3(x,y,z,20,C);
You can, of course, write logic to create the appropriate C array based on the data rather than hardcoding as shown.

  0 件のコメント

サインイン to comment.



Translated by