annotate toolboxes/FullBNT-1.0.7/KPMtools/assign_cols.m @ 0:cc4b1211e677 tip

initial commit to HG from Changeset: 646 (e263d8a21543) added further path and more save "camirversion.m"
author Daniel Wolff
date Fri, 19 Aug 2016 13:07:06 +0200
parents
children
rev   line source
Daniel@0 1 function M = assign_cols(cols, vals, M)
Daniel@0 2 % ASSIGN_COLS Assign values to columns of a matrix
Daniel@0 3 % function M = assign_cols(M, cols, vals, M)
Daniel@0 4 %
Daniel@0 5 % Example:
Daniel@0 6 % M = assign_cols(data, ones(1,N))
Daniel@0 7 % will construct a 1-of-K encoding of the data, where K=ncols=max(data) and N=nrows=length(data)
Daniel@0 8 %
Daniel@0 9 % Example:
Daniel@0 10 % M = zeros(3,2);
Daniel@0 11 % M = assign_cols([1 2 1], [10 20 30], M)
Daniel@0 12 % is equivalent to
Daniel@0 13 % M(1, 1) = 10
Daniel@0 14 % M(2, 2) = 20
Daniel@0 15 % M(3, 1) = 30
Daniel@0 16 %
Daniel@0 17
Daniel@0 18 if nargin < 3
Daniel@0 19 nr = length(cols);
Daniel@0 20 nc = max(cols);
Daniel@0 21 M = zeros(nr, nc);
Daniel@0 22 else
Daniel@0 23 [nr nc] = size(M);
Daniel@0 24 end
Daniel@0 25
Daniel@0 26 if 0
Daniel@0 27 for r=1:nr
Daniel@0 28 M(r, cols(r)) = vals(r);
Daniel@0 29 end
Daniel@0 30 end
Daniel@0 31
Daniel@0 32 if 1
Daniel@0 33 rows = 1:nr;
Daniel@0 34 ndx = subv2ind([nr nc], [rows(:) cols(:)]);
Daniel@0 35 M(ndx) = vals;
Daniel@0 36 end