File tree Expand file tree Collapse file tree 1 file changed +19
-17
lines changed Expand file tree Collapse file tree 1 file changed +19
-17
lines changed Original file line number Diff line number Diff line change 1
- function i = cell_index(lines , str , nl , ni )
2
- if nargin < 3
3
- nl = 1 ;
4
- end
5
- for i = nl : numel(lines )
6
- test = lines{i };
7
- if iscell(test ) || (size(test ,1 ) > 1 )
8
- test = [];
9
- continue ;
10
- end
11
- if size(test ,1 ) > size(test ,2 ), test = test ' ; end
12
- if ~ischar(test ), test = num2str(test ); end
13
- test = strfind(test ,str );
14
- if ~isempty(test ) && ((nargin < 4 ) || ((nargin > 3 ) && any(test == ni ))), break , end
15
- end
16
- if isempty(test )
17
- i = 0 ;
1
+ % Locate string "str" within a cell of strings "lines"
2
+ % Returns 0 if none
3
+ % Optional parameters:
4
+ % nl: starting index (default = 1)
5
+ % ni: returns location only if "str" is a substring starting from "ni"th character (default = none --> any match)
6
+ % Tibor Auer MRC CBU Cambridge 2012-2013
7
+
8
+ function r = cell_index(varargin )
9
+ nl = 1 ;
10
+ varargin{1 }(cellfun(@(x ) ~ischar(x ), varargin{1 })) = {' ' }; % ingore nonchar elements
11
+
12
+ if (nargin >= 3 ) && ~isempty(varargin{3 }), nl = varargin{3 }; end
13
+ if (nargin >= 4 )
14
+ r = find(cellfun(@(x ) ~isempty(x ) && (x == varargin{4 }),strfind(varargin{1 }(nl : end ),varargin{2 })));
15
+ else
16
+ r = find(cellfun(@(x ) ~isempty(x ),strfind(varargin{1 }(nl : end ),varargin{2 })));
18
17
end
18
+ if isempty(r ), r = 0 ; end
19
+ r = r ' ;
20
+ end
You can’t perform that action at this time.
0 commit comments