tp@0: function numvect = EDB1extrnums(Str,delim) tp@0: % EDB1extrnums - Extracts the numerical values in a text-string, separated by a given delimiter. tp@0: % Periods (.) are interpreted as decimal points. tp@0: % tp@0: % Input parameters: tp@0: % Str Text string, [nchars,1]. tp@0: % delim The delimiter to look for, e.g., comma, space, slash etc. tp@0: % Can be specified as the ASCII value or as the character: tp@0: % '/' tp@0: % tp@0: % Output parameters: tp@0: % numvect A list, [1,nnums], of the numerical values that were found. tp@0: % tp@0: % Uses no special functions tp@0: % tp@0: % ---------------------------------------------------------------------------------------------- tp@0: % This file is part of the Edge Diffraction Toolbox by Peter Svensson. tp@0: % tp@0: % The Edge Diffraction Toolbox is free software: you can redistribute it and/or modify tp@0: % it under the terms of the GNU General Public License as published by the Free Software tp@0: % Foundation, either version 3 of the License, or (at your option) any later version. tp@0: % tp@0: % The Edge Diffraction Toolbox is distributed in the hope that it will be useful, tp@0: % but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS tp@0: % FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. tp@0: % tp@0: % You should have received a copy of the GNU General Public License along with the tp@0: % Edge Diffraction Toolbox. If not, see . tp@0: % ---------------------------------------------------------------------------------------------- tp@0: % Peter Svensson (svensson@iet.ntnu.no) 20090719 tp@0: % tp@0: % numvect = EDB1extrnums(Str,delim); tp@0: tp@0: if isempty(Str) tp@0: numvect = []; tp@0: return tp@0: end tp@0: if nargin < 2 tp@0: iv = find( (Str>=48 & Str<=57) | (Str==46) | (Str==45) | (Str==101) | (Str==69) == 1); tp@0: else tp@0: iv = find( Str ~= delim ); tp@0: end tp@0: diffiv = diff(iv); tp@0: tp@0: if ~isempty(diffiv) tp@0: startindices = find(diffiv ~= 1); tp@0: else tp@0: startindices = []; tp@0: end tp@0: tp@0: if length(startindices) >= 1 tp@0: startpos = [iv(1) iv(startindices+1)]; tp@0: tp@0: numvect = zeros(1,length(startpos)); tp@0: for ii = 1:length(startpos)-1 tp@0: shortstr = Str(startpos(ii):startpos(ii+1)-1); tp@0: if nargin < 2 tp@0: shortstr = shortstr( find( (shortstr>=48 & shortstr<=57) | (shortstr==46) | (shortstr==45) | (shortstr==101) | (shortstr==69) == 1)); tp@0: else tp@0: shortstr = shortstr( find (shortstr ~= delim) ); tp@0: end tp@0: numvect(ii) = str2num(shortstr); tp@0: end tp@0: shortstr = Str(startpos(ii+1):length(Str)); tp@0: if nargin < 2 tp@0: shortstr = shortstr( find( (shortstr>=48 & shortstr<=57) | (shortstr==46) | (shortstr==45) | (shortstr==101) | (shortstr==69) == 1)); tp@0: else tp@0: shortstr = shortstr( find (shortstr ~= delim) ); tp@0: end tp@0: numvect(ii+1) = str2num(shortstr); tp@0: elseif length(iv) >= 1 tp@0: shortstr = Str(iv(1):length(Str)); tp@0: if nargin < 2 tp@0: shortstr = shortstr( find( (shortstr>=48 & shortstr<=57) | (shortstr==46) | (shortstr==45) | (shortstr==101) | (shortstr==69) == 1)); tp@0: else tp@0: shortstr = shortstr( find (shortstr ~= delim) ); tp@0: end tp@0: numvect = str2num(shortstr); tp@0: else tp@0: numvect = []; tp@0: end