You don't need cellfun, if you read the documentation, contains works natively on cell arrays of characters:
a = {'hello', 'world', 'friends'};
b = contains(a, 'o');
Which returns:
b =
1×3 logical array
1 1 0
Answer from sco1 on Stack OverflowMathWorks
mathworks.com › matlab › language fundamentals › data types › cell arrays
cellfun - Apply function to each cell in cell array - MATLAB
You can use cellfun to apply functions to cell arrays of character vectors and to string arrays. cellfun treats the two kinds of arrays identically. Create a cell array of character vectors that contains weekday names.
Octave
octave.sourceforge.io › octave › function › cellfun.html
Function Reference: cellfun - Octave Forge - SourceForge
Return the number of elements contained within each cell element. The number is the product of the dimensions of the object at each cell element. ... Return the size along the k-th dimension. ... Return 1 for elements of class. Additionally, cellfun accepts an arbitrary function func in the form of an inline function, function handle, or the name of a function (in a character string).
Northwestern University
ece.northwestern.edu › local-apps › matlabhelp › techdoc › ref › cellfun.html
cellfun (MATLAB Functions)
and returns the results in the double array D. Each element of D contains the value returned by fname for the corresponding element in C. The output array D is the same size as the cell array C. ... D = cellfun('size',C,k) returns the size along the k-th dimension of each element of C.
Mit
lost-contact.mit.edu › afs › inf.ed.ac.uk › group › teaching › matlab-help › R2016b › matlab › ref › cellfun.html
cellfun
[A1,...,Am] = cellfun(func,C1,...,Cn) calls the function specified by function handle func and passes elements from cell arrays C1,...,Cn, where n is the number of inputs to function func. Output arrays A1,...,Am, where m is the number of outputs from function func, contain the combined outputs from the function calls.
Omics
matlab.omics.wiki › matrix › cell-array › cellfun
Matlab by Examples - Convert cell array
id = find( cellfun(@(x) isequal(x,'Control'), C) ) 9 10 11 · % get location of all cell elements that contain substring 'B' (find cells whose output of strfind is not ('~') empty) id = find( cellfun(@(x) ~isempty(strfind(x,'B')), C) ) 5 6 7 · C(id) {'B1'} {'B2'} {'B3'} % get index of cells that starts with 'CTR' (control) at the first 3 letters ·
Google Groups
groups.google.com › g › comp.soft-sys.matlab › c › LZCshmKuczk
How to combine cellfun and strfind?
June 2, 2010 - Hello! Yes, I was looking if there is a file containing 001. in the name. So my function gave me back the position and I could collect the name. With the help of this group I am using now · file_position1=find(~cellfun('isempty', strfind(files_in_folder_names,'000.')));
Cloudmaven
cloudmaven.github.io › documentation › pdf › Doc10_BDSMATLABFunctionsInMETemplates.pdf pdf
Using MATLAB Functions in ME Templates
%Finding out which records contain valid formulae · %Angara will pass input argument so that · %t_in(formInd).data will be a vertical cell vector of char · %arrays (e.g. { 'C10H10NO3'; 'no reference'; 'whatever' }) mask = cellfun(@(x) ~isempty(regexp(x,formRegExp, 'once')), t_in(formInd).data); %names for the columns of the output table ·
MathWorks
mathworks.com › matlabcentral › answers › 432559-find-the-cell-array-contains-a-specific-string
find the cell array contains a specific string - MATLAB Answers - MATLAB Central
November 28, 2018 - https://www.mathworks.com/matlabcentral/answers/432559-find-the-cell-array-contains-a-specific-string#answer_349405 · Cancel Copy to Clipboard · Use strfind: >> idc = strfind(file,'bore'); % search for 'bore' in all cells. >> idx = ~cellfun('isempty',idc) % logical index, which cells contain 'bore'. idx = 1 ·
Altair
2021.help.altair.com › 2021 › compose › personal › en_us › topics › reference › oml_language › DataStructures › cellfun.htm
cellfun
Cell array which contains additional inputs for func. ... Uniform output type which specifies the class of R. By default, flag is 1, with R being a matrix. If flag is 0, R will be a cell ... Resulting output. ... function z=my_func(a) z=det(a); end a = {1, [1,2;3,4], [1,2,3;4,5,6;7,8,9]}; R = cellfun(@my_func,a)
Top answer 1 of 8
130
I guess the following code could do the trick:
strs = {'HA' 'KU' 'LA' 'MA' 'TATA'}
ind=find(ismember(strs,'KU'))
This returns
ans =
2
2 of 8
90
>> strs = {'HA' 'KU' 'LA' 'MA' 'TATA'};
>> tic; ind=find(ismember(strs,'KU')); toc
Elapsed time is 0.001976 seconds.
>> tic; find(strcmp('KU', strs)); toc
Elapsed time is 0.000014 seconds.
SO, clearly strcmp('KU', strs) takes much lesser time than ismember(strs,'KU')
Humgar
wonghoi.humgar.com › blog › 2016 › 07 › 23 › matlabs-cellfun-high-performance-trap
MATLAB Quirks: cellfun() high-performance trap | Rambling Nerd with a Plan
A = CELLFUN('isclass', C, CLASSNAME) returns true for each cell of C that contains an array of class CLASSNAME.
MathWorks
mathworks.com › matlabcentral › answers › 1637750-how-can-i-check-if-a-cell-array-contains-multiple-strings-without-loops
How can I check if a cell array contains multiple strings without loops ? - MATLAB Answers - MATLAB Central
January 27, 2022 - index = cellfun(@(c) contains(c,FileNames),p2,'UniformOutput',false);
UBC Computer Science
cs.ubc.ca › ~murphyk › Software › matlabTutorial › html › dataStructures.html
Strings, Cells, Structs, Containers, and Sets
B = cellfun(f,A) A = 'A ' 'test ' 'message, ' 'Which' 'contains ' '3 ' 'punctuation ' 'marks!' B = 0 1 1 0 1 1 1 1
Scribd
scribd.com › document › 360308349 › Cell-Fun
MATLAB cellfun Function Overview | PDF
JavaScript is disabled in your browser · Please enable JavaScript to proceed · A required part of this site couldn’t load. This may be due to a browser extension, network issues, or browser settings. Please check your connection, disable any ad blockers, or try using a different browser