# # function [G,M,mm]=htoind(H) # # Computes the indicator matrix for a data matrix # # Input: H, data matrix, with n rows and m columns. # It is assumed that each variable (= column of H) # is coded in integer values, with minimum = 1 # and maximum = number of categories. # # Output: G, the indicator matrix # M, row vector (1,m). Each entry of M equals # the number of categories of the corresponding # column of H. G has n rows and mm=sum(M) columns. # mm = sum(M), number of columns of G. # function [G,M,mm]=htoind(H) [n,m]=size(H); M=max(H); mm=sum(M); G=zeros(n,mm); for i=1:n, jmax=0; for v=1:m, jmin=jmax+1; jmax=jmin+M(v)-1; tt=zeros(1,M(v)); tt(H(i,v))=1; G(i,jmin:jmax)=tt; end end endfunction