SYMGRID Creates a grid that is symmetric around zero The function "mirrors" an existing grid around zero, and append the two grids. The original grid must contain positive values. Zero can be included (will not be repeated). The output is sorted in ascending order. FORMAT g = symgrid(g) OUT g Extended grid IN g Positive side of grid. Can include the value zero.
0001 % SYMGRID Creates a grid that is symmetric around zero 0002 % 0003 % The function "mirrors" an existing grid around zero, and append the two 0004 % grids. The original grid must contain positive values. Zero can be 0005 % included (will not be repeated). The output is sorted in ascending order. 0006 % 0007 % FORMAT g = symgrid(g) 0008 % 0009 % OUT g Extended grid 0010 % IN g Positive side of grid. Can include the value zero. 0011 0012 % 2007-11-29 Created by Patrick Eriksson. 0013 0014 0015 function g = symgrid(g) 0016 0017 if ~isnumeric(g) | ~isvector(g) 0018 error( 'Input variable *g* must be a vector.' ); 0019 end 0020 0021 if any( g < 0 ) 0022 error( 'Input variable *g* can not contain negative values.' ); 0023 end 0024 0025 0026 g = sort(g); 0027 0028 if g(1) == 0 0029 g = g([end:-1:2 1:end]); 0030 else 0031 g = g([end:-1:1 1:end]); 0032 end 0033 0034 0035 %- Make first part negative 0036 % 0037 [u,i] = min(g); 0038 % 0039 g(1:i) = -g(1:i);