1 function nvec = vecnorm(vec)
3 % VECNORM: Normalise the vectors.
11 % vec : An array of column vectors represented by a matrix of
12 % size (dim,nv), where is the dimension of the vector and
13 % nv the number of vectors.
17 % nvec : Normalised vectors, matrix the smae size as vec.
21 % Normalises the array of vectors, returning the unit vectors.
25 % Normalise the two vectors (0.0,2.0,1.3) and (1.5,3.4,2.3)
27 % nvec = vecnorm([0.0 1.5; 2.0 3.4; 1.3 2.3]);
29 % Copyright (C) 2000 Mark Spink
31 % This program is free software: you can redistribute it and/or modify
32 % it under the terms of the GNU General Public License as published by
33 % the Free Software Foundation, either version 2 of the License, or
34 % (at your option) any later version.
36 % This program is distributed in the hope that it will be useful,
37 % but WITHOUT ANY WARRANTY; without even the implied warranty of
38 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
39 % GNU General Public License for more details.
41 % You should have received a copy of the GNU General Public License
42 % along with this program. If not, see <http://www.gnu.org/licenses/>.
44 nvec = vec./repmat(sqrt(sum(vec.^2)),[size(vec,1) ones(1,ndims(vec)-1)]);