I'm writing a set of functions that will be used by colleagues who use older versions of MATLAB (2015a/2015b). In one of my functions I use contains()
which was only introduced in 2016b and is thus not backward compatible. I'd like to provide a workaround but I'm not quite sure how to go about this. The particular issue that I'm dealing with is as follows:
files = {'/some/path/sub001file','/some/path/sub002file','/some/path/sub003file'};
subjects = {'sub001','sub003'};
files = files(contains(files,subjects))
I'm looking for a way to replace the third line with one that will run on MATLAB2015a and later, and provides identical output. As an aside, since this is a rather small operation the readability of the code is more important than computational efficiency.
It's a bit convoluted, but the following will work,
idx = cellfun(@(c)~all(cellfun(@(d)isempty(strfind(c,d)),subjects)),files);
files = files(idx);