annotate _FullBNT/KPMtools/assign_cols.m @ 9:4ea6619cb3f5 tip

removed log files
author matthiasm
date Fri, 11 Apr 2014 15:55:11 +0100
parents b5b38998ef3b
children
rev   line source
matthiasm@8 1 function M = assign_cols(cols, vals, M)
matthiasm@8 2 % ASSIGN_COLS Assign values to columns of a matrix
matthiasm@8 3 % function M = assign_cols(M, cols, vals, M)
matthiasm@8 4 %
matthiasm@8 5 % Example:
matthiasm@8 6 % M = assign_cols(data, ones(1,N))
matthiasm@8 7 % will construct a 1-of-K encoding of the data, where K=ncols=max(data) and N=nrows=length(data)
matthiasm@8 8 %
matthiasm@8 9 % Example:
matthiasm@8 10 % M = zeros(3,2);
matthiasm@8 11 % M = assign_cols([1 2 1], [10 20 30], M)
matthiasm@8 12 % is equivalent to
matthiasm@8 13 % M(1, 1) = 10
matthiasm@8 14 % M(2, 2) = 20
matthiasm@8 15 % M(3, 1) = 30
matthiasm@8 16 %
matthiasm@8 17
matthiasm@8 18 if nargin < 3
matthiasm@8 19 nr = length(cols);
matthiasm@8 20 nc = max(cols);
matthiasm@8 21 M = zeros(nr, nc);
matthiasm@8 22 else
matthiasm@8 23 [nr nc] = size(M);
matthiasm@8 24 end
matthiasm@8 25
matthiasm@8 26 if 0
matthiasm@8 27 for r=1:nr
matthiasm@8 28 M(r, cols(r)) = vals(r);
matthiasm@8 29 end
matthiasm@8 30 end
matthiasm@8 31
matthiasm@8 32 if 1
matthiasm@8 33 rows = 1:nr;
matthiasm@8 34 ndx = subv2ind([nr nc], [rows(:) cols(:)]);
matthiasm@8 35 M(ndx) = vals;
matthiasm@8 36 end