Converts a cell array of strings or term of this to a numeric variable. Usage: x = fac2var( f [,v] ); f = n x 1 cell array of strings or term of this. v = 1 x k numeric vector of values for the k unique strings in f, in ascending order, =1:k if absent. x = n x 1 numeric vector.
0001 function x = fac2var( f, v ) 0002 0003 %Converts a cell array of strings or term of this to a numeric variable. 0004 % 0005 % Usage: x = fac2var( f [,v] ); 0006 % 0007 % f = n x 1 cell array of strings or term of this. 0008 % v = 1 x k numeric vector of values for the k unique strings in f, in 0009 % ascending order, =1:k if absent. 0010 % 0011 % x = n x 1 numeric vector. 0012 0013 if isa(f,'term') 0014 f=double(f)*(1:size(f,2))'; 0015 end 0016 [u,i,j]=unique(f); 0017 if nargin<2 0018 v=1:length(u); 0019 end 0020 x=v(j)';