MGRID Creates the d-dimensional grid with margin as 1-dimensional margin. g = mgrid(margin, d) creates a d-dimensional grid by 'folding' margin in d dimensions. The result is a d x length(margin)^d matrix representing all grid points (as column vectors) of the set margin^d. INPUT margin: margin of the grid to be created d: dimension of the grid created by Benedikt Rudolph DATE: 05-Sep-2012
0001 function g = mgrid(margin, d) 0002 % MGRID Creates the d-dimensional grid with margin as 1-dimensional margin. 0003 % 0004 % g = mgrid(margin, d) creates a d-dimensional grid by 'folding' margin 0005 % in d dimensions. The result is a d x length(margin)^d matrix representing 0006 % all grid points (as column vectors) of the set margin^d. 0007 % 0008 % INPUT margin: margin of the grid to be created 0009 % d: dimension of the grid 0010 % 0011 % created by Benedikt Rudolph 0012 % DATE: 05-Sep-2012 0013 0014 m = length(margin); 0015 g = zeros(d, m^d); % pre-init grid 0016 for i=1:d % iterate over all dimensions 0017 g(i,:) = reshape( repmat(margin, m^(i-1), m^(d-i)), 1, m^d ); 0018 end 0019 end