annotate toolboxes/FullBNT-1.0.7/KPMtools/unaryEncoding.m @ 0:e9a9cd732c1e tip

first hg version after svn
author wolffd
date Tue, 10 Feb 2015 15:05:51 +0000
parents
children
rev   line source
wolffd@0 1 function U = unaryEncoding(data, K)
wolffd@0 2 % unaryEncoding Encode data(s) as a 1-of-K column vector
wolffd@0 3 % function U = unaryEncoding(data, K)
wolffd@0 4 %
wolffd@0 5 % eg.
wolffd@0 6 % If data = [3 2 2] and K=3,
wolffd@0 7 % then U = [0 0 0
wolffd@0 8 % 0 1 1
wolffd@0 9 % 1 0 0]
wolffd@0 10
wolffd@0 11 if nargin < 2, K = max(data); end
wolffd@0 12 N = length(data);
wolffd@0 13 U = zeros(K,N);
wolffd@0 14 ndx = subv2ind([K N], [data(:)'; 1:N]');
wolffd@0 15 U(ndx) = 1;
wolffd@0 16 U = reshape(U, [K N]);