tp@0
|
1 function numvect = EDB1extrnums(Str,delim)
|
tp@0
|
2 % EDB1extrnums - Extracts the numerical values in a text-string, separated by a given delimiter.
|
tp@0
|
3 % Periods (.) are interpreted as decimal points.
|
tp@0
|
4 %
|
tp@0
|
5 % Input parameters:
|
tp@0
|
6 % Str Text string, [nchars,1].
|
tp@0
|
7 % delim The delimiter to look for, e.g., comma, space, slash etc.
|
tp@0
|
8 % Can be specified as the ASCII value or as the character:
|
tp@0
|
9 % '/'
|
tp@0
|
10 %
|
tp@0
|
11 % Output parameters:
|
tp@0
|
12 % numvect A list, [1,nnums], of the numerical values that were found.
|
tp@0
|
13 %
|
tp@0
|
14 % Uses no special functions
|
tp@0
|
15 %
|
tp@0
|
16 % ----------------------------------------------------------------------------------------------
|
tp@0
|
17 % This file is part of the Edge Diffraction Toolbox by Peter Svensson.
|
tp@0
|
18 %
|
tp@0
|
19 % The Edge Diffraction Toolbox is free software: you can redistribute it and/or modify
|
tp@0
|
20 % it under the terms of the GNU General Public License as published by the Free Software
|
tp@0
|
21 % Foundation, either version 3 of the License, or (at your option) any later version.
|
tp@0
|
22 %
|
tp@0
|
23 % The Edge Diffraction Toolbox is distributed in the hope that it will be useful,
|
tp@0
|
24 % but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
tp@0
|
25 % FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
tp@0
|
26 %
|
tp@0
|
27 % You should have received a copy of the GNU General Public License along with the
|
tp@0
|
28 % Edge Diffraction Toolbox. If not, see <http://www.gnu.org/licenses/>.
|
tp@0
|
29 % ----------------------------------------------------------------------------------------------
|
tp@0
|
30 % Peter Svensson (svensson@iet.ntnu.no) 20090719
|
tp@0
|
31 %
|
tp@0
|
32 % numvect = EDB1extrnums(Str,delim);
|
tp@0
|
33
|
tp@0
|
34 if isempty(Str)
|
tp@0
|
35 numvect = [];
|
tp@0
|
36 return
|
tp@0
|
37 end
|
tp@0
|
38 if nargin < 2
|
tp@0
|
39 iv = find( (Str>=48 & Str<=57) | (Str==46) | (Str==45) | (Str==101) | (Str==69) == 1);
|
tp@0
|
40 else
|
tp@0
|
41 iv = find( Str ~= delim );
|
tp@0
|
42 end
|
tp@0
|
43 diffiv = diff(iv);
|
tp@0
|
44
|
tp@0
|
45 if ~isempty(diffiv)
|
tp@0
|
46 startindices = find(diffiv ~= 1);
|
tp@0
|
47 else
|
tp@0
|
48 startindices = [];
|
tp@0
|
49 end
|
tp@0
|
50
|
tp@0
|
51 if length(startindices) >= 1
|
tp@0
|
52 startpos = [iv(1) iv(startindices+1)];
|
tp@0
|
53
|
tp@0
|
54 numvect = zeros(1,length(startpos));
|
tp@0
|
55 for ii = 1:length(startpos)-1
|
tp@0
|
56 shortstr = Str(startpos(ii):startpos(ii+1)-1);
|
tp@0
|
57 if nargin < 2
|
tp@0
|
58 shortstr = shortstr( find( (shortstr>=48 & shortstr<=57) | (shortstr==46) | (shortstr==45) | (shortstr==101) | (shortstr==69) == 1));
|
tp@0
|
59 else
|
tp@0
|
60 shortstr = shortstr( find (shortstr ~= delim) );
|
tp@0
|
61 end
|
tp@0
|
62 numvect(ii) = str2num(shortstr);
|
tp@0
|
63 end
|
tp@0
|
64 shortstr = Str(startpos(ii+1):length(Str));
|
tp@0
|
65 if nargin < 2
|
tp@0
|
66 shortstr = shortstr( find( (shortstr>=48 & shortstr<=57) | (shortstr==46) | (shortstr==45) | (shortstr==101) | (shortstr==69) == 1));
|
tp@0
|
67 else
|
tp@0
|
68 shortstr = shortstr( find (shortstr ~= delim) );
|
tp@0
|
69 end
|
tp@0
|
70 numvect(ii+1) = str2num(shortstr);
|
tp@0
|
71 elseif length(iv) >= 1
|
tp@0
|
72 shortstr = Str(iv(1):length(Str));
|
tp@0
|
73 if nargin < 2
|
tp@0
|
74 shortstr = shortstr( find( (shortstr>=48 & shortstr<=57) | (shortstr==46) | (shortstr==45) | (shortstr==101) | (shortstr==69) == 1));
|
tp@0
|
75 else
|
tp@0
|
76 shortstr = shortstr( find (shortstr ~= delim) );
|
tp@0
|
77 end
|
tp@0
|
78 numvect = str2num(shortstr);
|
tp@0
|
79 else
|
tp@0
|
80 numvect = [];
|
tp@0
|
81 end
|