Home > . > stra2num.m

stra2num

PURPOSE ^

'stra2num': transform letters (a, b, c) or numerical strings ('1','2'..) to the corresponding numbers

SYNOPSIS ^

function numres=stra2num(str)

DESCRIPTION ^

'stra2num': transform letters (a, b, c) or numerical strings ('1','2'..) to the corresponding numbers
--------------------------------------------
  function numres=stra2num(str)

 OUTPUT: 
 numres: number (double)

 INPUT:
 str: string corresponding to a number or a letter 'a' 'b',.., otherwise the output is empty

 see also num2stra, name_generator, name2display

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 %'stra2num': transform letters (a, b, c) or numerical strings ('1','2'..) to the corresponding numbers
0002 %--------------------------------------------
0003 %  function numres=stra2num(str)
0004 %
0005 % OUTPUT:
0006 % numres: number (double)
0007 %
0008 % INPUT:
0009 % str: string corresponding to a number or a letter 'a' 'b',.., otherwise the output is empty
0010 %
0011 % see also num2stra, name_generator, name2display
0012 
0013 function numres=stra2num(str)
0014 numres=[]; %default
0015 if double(str) >= 48 & double(str) <= 57 % = test for number strings
0016     numres=str2num(str);
0017 elseif double(str) >= 65 & double(str) <= 90 % test on ascii code for capital letters
0018     numres=double(str)-64; %change capital letters to corresponding number in the alphabet
0019 elseif double(str) >= 97 & double(str) <= 122 % test on ascii code for small letters
0020     numres=double(str)-96; %change small letters to corresponding number in the alphabet
0021 end

Generated on Fri 13-Nov-2009 11:17:03 by m2html © 2003