![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/272658/image.png)
Removing the origin from the 3D meshgrid?
조회 수: 5 (최근 30일)
이전 댓글 표시
Suppose I want to plot level surfaces of a function of 3 variables, and suppose this function has a 1/(r^n) dependence. Where r = sqrt(X.^2 + Y.^2 + Z.^2) is the distance from the origin. Naturally I want to filter the origin from the [X,Y,Z] meshgrid to avoid singularities. How do I do this? Here is my attempt.
I thought about using the nonzero function on vectors x,y, and z and then forming the meshgrid but then that excludes entire coordinate planes.
%1) Create the grid
n = 50;
rmax = 2400;
x = linspace(-rmax,rmax,n+1);
y = linspace(-rmax,rmax,n+1);
z = linspace(-rmax,rmax,n+1);
[X,Y,Z] = meshgrid(x,y,z);
%2) Create R
R = sqrt(X.^2 + Y.^2 + Z.^2);
R1 = R.^(-1); %Create the reciprocal of R
idx = isnan(R1); %Find all the NaNs
R(idx) = []; %Delete all the NaN's in R, do the same for X,Y,Z
X(idx) = [];
Y(idx) = [];
Z(idx) = [];
Despite there being obvious singularities in R1 (because x,y,z each contain zero) I am still getting R,X,Y,and Z to have the same number of elements as they did before.
I would greatly appreciate any help.
댓글 수: 0
채택된 답변
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Surface and Mesh Plots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!