'.' '..' 'H66000.526' 'H66001.526' 'H66002.526' 'H66003.526' 'H66004.526'
How can I combine cellfun and strfind to find '001.' in the other strings, please?
Thank you.
cellfun(@(IDX) ~isempty(IDX), strfind(TheCell, '.001'))
This will return a logical vector, one per row, true indicating that the
row matched. Is that what you were seeking, or were you looking for
the indices?
Positions = zeros(length(TheCell),1);
T = strfind(TheCell, '.001);
E = cellfun(@isempty, T);
Positions(~E) = cellfun(@(IDX) IDX(1), T(~E));
This will create Positions as 0 for rows that do not contain the string
and as the index of the first occurance of 001. for the rows that do.
one of the many solutions
c={'.','..','ab001','ab002','ac001'};
ix=~cellfun(@isempty,regexp(c,'001'))
% ix = 0 0 1 0 1
us
file_position1=find(~cellfun('isempty', strfind(files_in_folder_names,'000.')));
and by knowing the position I will get the full name later.
Thank you as well for your suggestions.
The output then would be a cell array with the same amount of elements as XX. So the statement I am looking for should behave like
str = {'001','b0'};
c={'.','..','ab001','ab002','ac001'};
ix=~cellfun(@isempty,regexp(c,str))
ix{1} = [0 0 1 0 0];
ix{2} = [0 0 1 1 0];
Any ideas?
one of the (more contrived) solutions
str={'001','b0'};
c={'.','..','ab001','ab002','ac001'};
ix=arrayfun(@(x) ~cellfun(@isempty,regexp(c,str(x))),1:numel(str),'uni',false);
ix=cat(1,ix{:})
%{
% ix =
0 0 1 0 1
0 0 1 1 0
%}
us
tic
for i = 1:n
for j = 1:numel(id)
ix{j} = ~cellfun(@isempty,regexp(c,str{j}));
end
end
toc
to be 2.5 times faster. I went on to check other examples and found arrayfun to always be slower than the for-loop it is replacing. When is it, performance-wise, an advantage to use arrayfun?
Never.
Only cellfun has 3 syntaxes (the last 3 ones listed in the help) which may be at least as fast as a loop.
Oleg
For even more speed use 'isempty' instead of @isempty.
... as has been shown many(!) times on this newsgroup.
With few exception, arrayfun is cellfun are deceit features introduced by Mathworks few years ago. They are essentially disguised for-loop. Similar topic has been discussed in the pass:
http://www.mathworks.com/matlabcentral/newsreader/view_thread/253815
Bruno