[8] | 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 | %
|
---|
| 11 | % see also num2stra, name_generator, name2display
|
---|
| 12 |
|
---|
[809] | 13 | %=======================================================================
|
---|
[1027] | 14 | % Copyright 2008-2018, LEGI UMR 5519 / CNRS UGA G-INP, Grenoble, France
|
---|
[809] | 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 |
|
---|
[8] | 31 | function numres=stra2num(str)
|
---|
[353] | 32 | numres=[]; %default
|
---|
[8] | 33 | if double(str) >= 48 & double(str) <= 57 % = test for number strings
|
---|
[89] | 34 | numres=str2double(str);
|
---|
[8] | 35 | elseif 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
|
---|
| 37 | elseif 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
|
---|
| 39 | end
|
---|