# source:trunk/src/stra2num.m@979

Last change on this file since 979 was 977, checked in by g7moreau, 8 years ago
• Update Copyright 2008-2017 notice
File size: 1.8 KB
Line
1%'stra2num': transform letters (a, b, c) or numerical strings ('1','2'..) to the corresponding numbers
2%--------------------------------------------
3%  function numres=stra2num(str)
4%
5% OUTPUT:
6% numres: number (double)
7%
8% INPUT:
9% str: string corresponding to a number or a letter 'a' 'b',.., otherwise the output is empty
10%
12
13%=======================================================================
14% Copyright 2008-2017, LEGI UMR 5519 / CNRS UGA G-INP, Grenoble, France
15%   http://www.legi.grenoble-inp.fr
16%   Joel.Sommeria - Joel.Sommeria (A) legi.cnrs.fr
17%
18%     This file is part of the toolbox UVMAT.
19%
20%     UVMAT is free software; you can redistribute it and/or modify
21%     it under the terms of the GNU General Public License as published
22%     by the Free Software Foundation; either version 2 of the license,
23%     or (at your option) any later version.
24%
25%     UVMAT is distributed in the hope that it will be useful,
26%     but WITHOUT ANY WARRANTY; without even the implied warranty of
27%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
28%     GNU General Public License (see LICENSE.txt) for more details.
29%=======================================================================
30
31function numres=stra2num(str)
32numres=[]; %default
33if double(str) >= 48 & double(str) <= 57 % = test for number strings
34    numres=str2double(str);
35elseif double(str) >= 65 & double(str) <= 90 % test on ascii code for capital letters
36    numres=double(str)-64; %change capital letters to corresponding number in the alphabet
37elseif double(str) >= 97 & double(str) <= 122 % test on ascii code for small letters
38    numres=double(str)-96; %change small letters to corresponding number in the alphabet
39end
Note: See TracBrowser for help on using the repository browser.