2013-05-30 4 views
-3

그리드 내부에 공이있는 3D 그리드를 만드는 함수를 작성하고 싶습니다. 3D이어야합니다. this example을 찾았는데 정확히 원하는 것입니다. 그러나이 파일을 함수 m- 파일에 어떻게 추가 할 수 있는지 전혀 알지 못합니다.Matlab : 3D 그리드를 만들려면 어떻게해야합니까?

이 내 코드입니다 :

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 

답변

1

the example보고 후, 그 makeGrid가 함수 인, 해당 웹 사이트에 말했다. 함수는 3rd party, open source, Matlab toolbox의 일부입니다.
도구 상자가있는 경우 (다운로드를 위해 웹 사이트에 로그인이 필요함) makeGrid 함수가 있어야합니다.

당신은, 당신은 시도 할 수없는 경우 matlab에의 기능 meshgrid : 위의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; 

및 사용 중 하나

[X,Y,Z] = meshgrid(xgv,ygv,zgv); 
관련 문제