Why do you want to use a loop? To improve the speed? Then there are better methods:
- cellfun('isempty', f1) is faster than cellfun(@isempty, f1), but it does not work with strings. Are the inputs char vectors or strings?
- length(nomatch(nomatch == 0)): Faster: numel(s) - sum(nomatch).
- nomatch = cellfun(@isempty, strfind(s,n)): Faster: nomatch = ~contains(s, n)
function out = motifsupport(s,n)
out = sum(contains(s, n)) / numel(s);
end
Is there still a need to use a loop?
function out = motifsupport(s, n)
count = 0;
for is = 1:numel(s)
count = count + any(strfind(s{is}, n));
end
out = count / nuzmel(s);
end