필터 지우기
필터 지우기

Removing the origin from the 3D meshgrid?

조회 수: 5 (최근 30일)
Omar Azami
Omar Azami 2020년 2월 19일
답변: darova 2020년 2월 19일
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.

채택된 답변

darova
darova 2020년 2월 19일
Make selected values even (2 4 6 .. 98 100)

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by