Mercurial > hg > camir-aes2014
annotate toolboxes/FullBNT-1.0.7/KPMtools/assign_cols.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 M = assign_cols(cols, vals, M) |
wolffd@0 | 2 % ASSIGN_COLS Assign values to columns of a matrix |
wolffd@0 | 3 % function M = assign_cols(M, cols, vals, M) |
wolffd@0 | 4 % |
wolffd@0 | 5 % Example: |
wolffd@0 | 6 % M = assign_cols(data, ones(1,N)) |
wolffd@0 | 7 % will construct a 1-of-K encoding of the data, where K=ncols=max(data) and N=nrows=length(data) |
wolffd@0 | 8 % |
wolffd@0 | 9 % Example: |
wolffd@0 | 10 % M = zeros(3,2); |
wolffd@0 | 11 % M = assign_cols([1 2 1], [10 20 30], M) |
wolffd@0 | 12 % is equivalent to |
wolffd@0 | 13 % M(1, 1) = 10 |
wolffd@0 | 14 % M(2, 2) = 20 |
wolffd@0 | 15 % M(3, 1) = 30 |
wolffd@0 | 16 % |
wolffd@0 | 17 |
wolffd@0 | 18 if nargin < 3 |
wolffd@0 | 19 nr = length(cols); |
wolffd@0 | 20 nc = max(cols); |
wolffd@0 | 21 M = zeros(nr, nc); |
wolffd@0 | 22 else |
wolffd@0 | 23 [nr nc] = size(M); |
wolffd@0 | 24 end |
wolffd@0 | 25 |
wolffd@0 | 26 if 0 |
wolffd@0 | 27 for r=1:nr |
wolffd@0 | 28 M(r, cols(r)) = vals(r); |
wolffd@0 | 29 end |
wolffd@0 | 30 end |
wolffd@0 | 31 |
wolffd@0 | 32 if 1 |
wolffd@0 | 33 rows = 1:nr; |
wolffd@0 | 34 ndx = subv2ind([nr nc], [rows(:) cols(:)]); |
wolffd@0 | 35 M(ndx) = vals; |
wolffd@0 | 36 end |