Removing the origin from the 3D meshgrid?

3 ビュー (過去 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 Center および File ExchangeSurface and Mesh Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by