필터 지우기
필터 지우기

Plot a 3d domain with colors determined by 3d array

조회 수: 8 (최근 30일)
Michael Hennessey
Michael Hennessey 2021년 1월 15일
편집: Cris LaPierre 2021년 1월 16일
I have 3 vectors: X(N), Y(N), Z(N) that define a space in 3D, let's call it D = [X(1),X(N)] x [Y(1),Y(N)] x [Z(1),Z(N)]. I have a matrix with values at each point in D, called out(N,N,N). How can I plot the space D as points with colors determined by the values given in out(N,N,N)?
  댓글 수: 2
Cris LaPierre
Cris LaPierre 2021년 1월 15일
What type of 3D plot are you creating? Scatter? Line? Contour? Mesh? Surface?
Michael Hennessey
Michael Hennessey 2021년 1월 15일
I'd be happy with either a scatter plot or a contour - whichever's easier really.

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

답변 (1개)

Cris LaPierre
Cris LaPierre 2021년 1월 15일
편집: Cris LaPierre 2021년 1월 16일
I would use the following syntax for scatter3
Note that 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.
Convert out into a vector using the colon operator: C = out(:);
To work, X, Y, and Z will have to be the same size as out. You can use meshgrid for that.
Here's a simple example. Note that the color of the markers has nothing to do with their x,y or z locations. It is coming from C.
X=1:5;
Y=11:15;
Z=0.1:0.1:0.5;
[x,y,z]=meshgrid(X,Y,Z);
% Create random values for the color
C = rand(size(x));
scatter3(x(:),y(:),z(:),[],C(:))
colorbar
  댓글 수: 1
Michael Hennessey
Michael Hennessey 2021년 1월 16일
That works great! I was missing the meshgrid command in my previous attempts. Thank you!

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

카테고리

Help CenterFile Exchange에서 Surface and Mesh Plots에 대해 자세히 알아보기

태그

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by