我想写一个函数,它创建一个带有球内网格的3D网格。它应该是3D。 我找到this example,这正是我想要的,但我不知道如何在函数m文件中添加它。
这是我的代码:
function kgrid = makeGrid(Nx, dx, Ny, dy);
% create the computational grid
Nx = 64; % number of grid points in the x direction
Ny = 64; % number of grid points in the y direction
Nz = 64; % number of grid points in the z direction
dx = 0.1e-3; % grid point spacing in the x direction [m]
dy = 0.1e-3; % grid point spacing in the y direction [m]
dz = 0.1e-3; % grid point spacing in the z direction [m]
kgrid = makeGrid(Nx, dx, Ny, dy, Nz, dz);
end
答案 0 :(得分:1)
在查看the example后,它在该网站上说makeGrid
是一个功能。该函数是3rd party, open source, Matlab toolbox的一部分
如果您有该工具箱(显然您需要在网站上登录),您应该具有makeGrid
功能。
如果不这样做,可以尝试使用Matlab的函数meshgrid
:
xgv = linspace(0,1,64); % this will give you 64 points between 0 and 1
ygv = linspace(0,1,64);
zgv = linspace(0,1,64);
或
xgv = 0:1e-4:1; % this will give you a spacing of 1e-4 between the gridpoints
ygv = 0:1e-4:1;
zgv = 0:1e-4:1;
然后使用以上任一和meshgrid
:
[X,Y,Z] = meshgrid(xgv,ygv,zgv);