Home > wafo > wstats > cl2cnr.m

# cl2cnr

## PURPOSE

Column Label to Column Number

I1 = cl2cnr(I)

## DESCRIPTION

``` CL2CNR Column Label to Column Number

CALL:  I1 = cl2cnr(I)

I1 = matrix of column numbers
I  = character array of column labels.

CL2CNR transforms a column label into a column number, i.e.,
convert 'A'-'Z' to 1-25, 'a'-'z' to 26-50 and ' ' to 0.

CL2CNR is useful in conjuction with SUDG and CDR

## CROSS-REFERENCE INFORMATION

This function calls:
 double Convert to double precision. ischar True for character array (string). warning Display warning message; disable or enable warning messages.
This function is called by:
 alias Alias structure of a fractional design. cdr Complete Defining Relation ffd Two-level Fractional Factorial Design

## SOURCE CODE

```001 function I1 = cl2cnr(I)
002 %CL2CNR Column Label to Column Number
003 %
004 % CALL:  I1 = cl2cnr(I)
005 %
006 % I1 = matrix of column numbers
007 % I  = character array of column labels.
008 %
009 % CL2CNR transforms a column label into a column number, i.e.,
010 % convert 'A'-'Z' to 1-25, 'a'-'z' to 26-50 and ' ' to 0.
011 %
012 % CL2CNR is useful in conjuction with SUDG and CDR
013 %
015
016
017 % Tested on: Matlab 5.3
018 % History:
019 % By Per A. Brodtkorb 16.03.2001
020
021 if ischar(I)
022   sgn = ones(size(I));
023   sgn(I=='-') = -1;
024   sgn = prod(sgn,2);
025
026   I1 = double(I)-64;     % Convert A-Z to 1-25
027   I1(I1<0)=0;            % Convert ' ' to 0
028   k = find(I>=97);
029   if any(k),             % Convert a-z to 26-50
030     I1(k) = I(k)-96+26;
031   end
032   I1 = sort(I1,2);
033
034   if any(I1(:)>50), warning('Illegal column label!'), end
035   I1(:,end) = I1(:,end).*sgn;
036 else
037   I1 = I;
038 end
039
040 % Remove starting zeros
041 [ix,iy] = find(I1~=0);
042 iy  = min(iy);
043 if ~isempty(iy) & (iy>1),  I1 = I1(:,iy:end);  end
044
045 return
046```

Mathematical Statistics
Centre for Mathematical Sciences
Lund University with Lund Institute of Technology

Comments or corrections to the WAFO group

Generated on Thu 06-Oct-2005 02:21:16 for WAFO by m2html © 2003