Check if a path name contains a certain folder name anywhere
if any(findstr(PathName, '/Sub/')) ...
Because FINDSTR searches the shorter string in the longer one, the condition is true for the path name '/' also.
Modern Matlab version use STRFIND(String, Pattern) and afaik FINDSTR will be deprecated. But the program containing the example was developped under Matlab 5.3. Fixing the bug by changing FINDSTR to STRFIND is not trivial, if the strings are created dynamically, e.g. FINDSTR(a{i}, ['@', b{j}]).
At least in Matlab 2009a the toolbox functions contains a lot of these pitfalls, e.g. Signal\PMEM: "if ~isempty(findstr(flag, 'CORR')), ...", which triggers for 'OR' also.
5 Comments
Direct link to this comment
https://fr.mathworks.com/matlabcentral/answers/1759-dumb-mistakes-we-make-with-matlab#comment_3342
Direct link to this comment
https://fr.mathworks.com/matlabcentral/answers/1759-dumb-mistakes-we-make-with-matlab#comment_3342
Direct link to this comment
https://fr.mathworks.com/matlabcentral/answers/1759-dumb-mistakes-we-make-with-matlab#comment_3381
Direct link to this comment
https://fr.mathworks.com/matlabcentral/answers/1759-dumb-mistakes-we-make-with-matlab#comment_3381
Direct link to this comment
https://fr.mathworks.com/matlabcentral/answers/1759-dumb-mistakes-we-make-with-matlab#comment_3426
Direct link to this comment
https://fr.mathworks.com/matlabcentral/answers/1759-dumb-mistakes-we-make-with-matlab#comment_3426
Direct link to this comment
https://fr.mathworks.com/matlabcentral/answers/1759-dumb-mistakes-we-make-with-matlab#comment_3499
Direct link to this comment
https://fr.mathworks.com/matlabcentral/answers/1759-dumb-mistakes-we-make-with-matlab#comment_3499
Direct link to this comment
https://fr.mathworks.com/matlabcentral/answers/1759-dumb-mistakes-we-make-with-matlab#comment_3876
Direct link to this comment
https://fr.mathworks.com/matlabcentral/answers/1759-dumb-mistakes-we-make-with-matlab#comment_3876
Sign in to comment.