source: trunk/src/stra2num.m @ 1180

Last change on this file since 1180 was 1180, checked in by sommeria, 3 weeks ago

various bugs repaired,Relabeling frames installed for multitif

File size: 1.7 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%
11% see also num2stra, name_generator, name2display
12
13%=======================================================================
14% Copyright 2008-2024, LEGI UMR 5519 / CNRS UGA G-INP, Grenoble, France
15%   http://www.legi.grenoble-inp.fr
16%   Joel.Sommeria - Joel.Sommeria (A) univ-grenoble-alpes.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=str2double(str); %default
33if isnan(numres)
34   if double(str) >= 65 & double(str) <= 90 % test on ascii code for capital letters
35    numres=double(str)-64; %change capital letters to corresponding number in the alphabet
36  elseif double(str) >= 97 & double(str) <= 122 % test on ascii code for small letters
37    numres=double(str)-96; %change small letters to corresponding number in the alphabet
38   end
39end
Note: See TracBrowser for help on using the repository browser.