1 function [B,BLab]=cat2bin(D, Label, MODE)
2 % CAT2BIN converts categorial into binary data
3 % each category of each column in D is converted into a logical column
6 % [B,BinLabel] = cat2bin(C,Label);
7 % [B,BinLabel] = cat2bin(C,Label,MODE)
11 % Label description of each column in C
12 % BinLabel description of each column in B
13 % MODE default [], ignores NaN
14 % 'notIgnoreNAN' includes binary column for NaN
15 % 'IgnoreZeros' zeros do not get a separate category
16 % 'IgnoreZeros+NaN' zeros and NaN are ignored
19 % cat2bin([1;2;5;1;5]) results in
26 % $Id: cat2bin.m 9033 2011-11-08 20:58:07Z schloegl $
27 % Copyright (C) 2009 by Alois Schloegl <alois.schloegl@gmail.com>
28 % This function is part of the NaN-toolbox
29 % http://pub.ist.ac.at/~schloegl/matlab/NaN/
31 % This program is free software; you can redistribute it and/or
32 % modify it under the terms of the GNU General Public License
33 % as published by the Free Software Foundation; either version 3
34 % of the License, or (at your option) any later version.
36 % This program is distributed in the hope that it will be useful,
37 % but WITHOUT ANY WARRANTY; without even the implied warranty of
38 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
39 % GNU General Public License for more details.
41 % You should have received a copy of the GNU General Public License
42 % along with this program; if not, write to the Free Software
43 % Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
56 h = histo_mex(D(:,m));
58 if strcmpi(MODE,'notIgnoreNaN')
60 elseif strcmpi(MODE,'IgnoreZeros')
62 elseif strcmpi(MODE,'IgnoreZeros+NaN')
63 x = x((x~=0) & (x==x));
69 B(k, c + find(D(k,m)==x)) = 1;
71 B(k, c + length(x)) = 1;
80 BLab{k1} = ['#',int2str(m),':',int2str(x(k))];
82 BLab{k1} = [Label{m},':',int2str(x(k))];
89 %!assert(cat2bin([1;2;5;1;5]),[1,0,0;0,1,0;0,0,1;1,0,0;0,0,1])