-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnormc.m
More file actions
31 lines (27 loc) · 795 Bytes
/
normc.m
File metadata and controls
31 lines (27 loc) · 795 Bytes
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
29
30
31
function y = normc(x)
%NORMC Normalize columns of matrices.
%
% <a href="matlab:doc normc">normc</a>(X) takes a single matrix or cell array of matrices and returns
% the matrices with columns normalized to a length of one.
%
% Here the columns of a random matrix are randomized.
%
% x = <a href="matlab:doc rands">rands</a>(4,8);
% y = <a href="matlab:doc normc">normc</a>(x)
%
% See also NORMR.
% Mark Beale, 1-31-92
% Copyright 1992-2010 The MathWorks, Inc.
if nargin < 1,error(message('nnet:Args:NotEnough')); end
wasMatrix = ~iscell(x);
x = nntype.data('format',x,'Data');
y = cell(size(x));
for i=1:numel(x)
xi = x{i};
rows = size(xi,1);
n = 1 ./ sqrt(sum(xi.*xi,1));
yi = xi .* n(ones(1,rows),:);
yi(~isfinite(yi)) = 1;
y{i} = yi;
end
if wasMatrix, y = y{1}; end