Last change
on this file since 13646 was 13646, checked in by Mathieu Morlighem, 12 years ago |
CHG: cosmetics, removed multiple blank lines
|
File size:
857 bytes
|
Line | |
---|
1 | %
|
---|
2 | % function to find and read the first or last positive integer
|
---|
3 | % in a character string.
|
---|
4 | %
|
---|
5 | % function [aint]=str2int(astr,cfl)
|
---|
6 | %
|
---|
7 | function [aint]=str2int(astr,cfl);
|
---|
8 |
|
---|
9 | aint=[];
|
---|
10 |
|
---|
11 | if ~exist('cfl','var') || strncmpi(cfl,'f',1)
|
---|
12 | i=1;
|
---|
13 |
|
---|
14 | while (i <= length(astr))
|
---|
15 | if (astr(i) >= '0' && astr(i) <= '9')
|
---|
16 | aint=sscanf(astr(i:length(astr)),'%d',[1,1]);
|
---|
17 | return
|
---|
18 | else
|
---|
19 | i=i+1;
|
---|
20 | end
|
---|
21 | end
|
---|
22 |
|
---|
23 | elseif strncmpi(cfl,'l',1)
|
---|
24 | i=length(astr);
|
---|
25 | ifound=false;
|
---|
26 |
|
---|
27 | while (i >= 1)
|
---|
28 | if (astr(i) >= '0' && astr(i) <= '9')
|
---|
29 | ifound=true;
|
---|
30 | i=i-1;
|
---|
31 | elseif ~ifound
|
---|
32 | i=i-1;
|
---|
33 | else
|
---|
34 | aint=sscanf(astr(i+1:length(astr)),'%d',[1,1]);
|
---|
35 | return
|
---|
36 | end
|
---|
37 | end
|
---|
38 |
|
---|
39 | if ifound
|
---|
40 | aint=sscanf(astr,'%d',[1,1]);
|
---|
41 | return
|
---|
42 | end
|
---|
43 | end
|
---|
44 |
|
---|
45 | end
|
---|
Note:
See
TracBrowser
for help on using the repository browser.