How can I change the color of the face of a cube created using the slice command?

7 ビュー (過去 30 日間)
Parker Jebens
Parker Jebens 2021 年 4 月 12 日
回答済み: Mathieu NOE 2021 年 4 月 13 日
Using this code:
[X,Y,Z] = meshgrid(0:3);
V = X.*exp(-X.^2-Y.^2-Z.^2);
xslice = 0:3;
yslice = 0:3;
zslice = 0:3;
slice(X,Y,Z,V,xslice,yslice,zslice,'nearest'),xlabel('X-Axis'),ylabel('Y-Axis'),zlabel('Z-Axis')
I was able to make the shape I needed but have been unable to change the face colors. Colormap has not allowed me to change faces individually. The closest I got was through the figure editor but I cannot import the changes into my code so that it gives me the colors I want on the faces.

回答 (1 件)

Mathieu NOE
Mathieu NOE 2021 年 4 月 13 日
hello
use handles to modify face colors
here I changes all external faces to black
[X,Y,Z] = meshgrid(0:3);
V = X.*exp(-X.^2-Y.^2-Z.^2);
xslice = 0:3;
yslice = 0:3;
zslice = 0:3;
h = slice(X,Y,Z,V,xslice,yslice,zslice,'nearest'),xlabel('X-Axis'),ylabel('Y-Axis'),zlabel('Z-Axis')
set(h(1),'FaceColor',[0 0 0])
set(h(4),'FaceColor',[0 0 0])
set(h(5),'FaceColor',[0 0 0])
set(h(8),'FaceColor',[0 0 0])
set(h(9),'FaceColor',[0 0 0])
set(h(12),'FaceColor',[0 0 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