-
Notifications
You must be signed in to change notification settings - Fork 3
/
gridspace.m
28 lines (25 loc) · 1007 Bytes
/
gridspace.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
function grd = gridspace(p1, p2, inc)
% This function computes the coordinates of a rectangular grid space
% where P1 and P2 denote the oposite corners of the rectangle. INC is
% the increment between grid points.
%
% grd = gridspace(p1, p2, inc)
%
% The output GRD is a cell array with N vectors containing coordinates in the space
% where N is the same dimension as vectors P1 and P2. If INC is a scaler
% then the increment between gridpoints is the same in all dimensions.
%
% Written by Kevin D. Donohue ([email protected]) July 2005
% Determine number of dimesnsion for grid.
dim = length(p1);
% Determine nature of increment in each dimension
if length(inc) < dim
inc = inc(1)*ones(1,dim); % make increments the same in all directions
end
% Initalize output cell array
grd = cell(1,dim);
% Create grid vectors from the smaller value corner coordinate to the
% larger one
for k=1:dim
grd{k} = [min([p1(k),p2(k)]):inc(k):max([p1(k),p2(k)])];
end