Well, simply define a new anonymous function as @(x) myFunc(x,4) and use it this way:

F = cellfun(@(x) myFunc(x,4), C)
Answer from knedlsepp on Stack Overflow
๐ŸŒ
MathWorks
mathworks.com โ€บ matlab โ€บ language fundamentals โ€บ data types โ€บ cell arrays
cellfun - Apply function to each cell in cell array - MATLAB
You can return A as a cell array when func returns values that cannot be concatenated into an array. You can use Name,Value pair arguments with the input arguments of either of the previous syntaxes. ... [A1,...,Am] = cellfun(___) returns multiple output arrays A1,...,Am when func returns m ...
Discussions

matlab - Application of cellfun with multiple arguments - Stack Overflow
So I have a lot of cell manipulation in code I'm writing right now where it helps greatly to have cell functions of two arguments (e.g., to concatenate arrays in cells of the same size). However, M... More on stackoverflow.com
๐ŸŒ stackoverflow.com
is it possible to use multiple functions in cellfun
https://www.mathworks.com/matlabcentral/answers/2019321-is-it-possible-to-use-multiple-functions-in-cellfun ... cellfun's first argument - function "func", which contains multiple lines/functions "func1", "func2", ... More on mathworks.com
๐ŸŒ mathworks.com
4
0
September 11, 2023
Using Cellfun for multiple inputs
When you define the anonymous function (@(x) extractFeatures(G, points)), you define it as a function of x (@(x)), but do not use x in the function body (extractFeatures(G, points)). I believe you meant extractFeatures(x, points), or, alternatively, @(G). Error messages in anonymous functions are sometimes confusing, but you are probably getting an error that would lead you to this. More on reddit.com
๐ŸŒ r/matlab
4
2
May 1, 2018
can i used cellfun with a function which has more than one input?
Hello I have a function as follows [ chart_datavortex ] = chart_funcv( 'AUD_USD', New_dataopenbidx, New_datahighbidx, New_datalowbidx,New_datax, New_datavol ) The function takes 6 inputs, h... More on mathworks.com
๐ŸŒ mathworks.com
1
3
October 8, 2017
๐ŸŒ
MathWorks
mathworks.com โ€บ matlabcentral โ€บ answers โ€บ 375731-cellfun-for-function-with-multiple-inputs
cellfun for function with multiple inputs - MATLAB Answers - MATLAB Central
January 5, 2018 - 'Later' in your case means in the cellfun statement, where each element of the cell array will successively be given to that function as the 'a' argument. ... https://www.mathworks.com/matlabcentral/answers/375731-cellfun-for-function-with-multiple-inputs#comment_521794
๐ŸŒ
MathWorks
mathworks.com โ€บ matlabcentral โ€บ answers โ€บ 2019321-is-it-possible-to-use-multiple-functions-in-cellfun
is it possible to use multiple functions in cellfun - MATLAB Answers - MATLAB Central
September 11, 2023 - https://www.mathworks.com/matlabcentral/answers/2019321-is-it-possible-to-use-multiple-functions-in-cellfun#answer_1306981 ... No, it is not possible to directly use multiple functions as the first argument of cellfun in the way you described.
๐ŸŒ
Reddit
reddit.com โ€บ r/matlab โ€บ using cellfun for multiple inputs
r/matlab on Reddit: Using Cellfun for multiple inputs
May 1, 2018 -

Hiya,

I'm trying to specifically use cellfun to use the function extractFeatures on multiple detected points from a SURF detection in the computer vision toolbox. The problem I'm having is that the inputs are both cell arrays which doesn't allow me to put one of them as the cell array. Should add I'm trying to extract features for 118 images.

Here is what I've tried:

g = cellfun(@rgb2gray,images,'UniformOutput',false);
points = cellfun(@detectSURFFeatures,g,'UniformOutput',false);
[features, valid_points] = cellfun(@(x) extractFeatures(G, points), g);

Where g & points are cell arrays with size 1x118.

Any help is much appreciated.

๐ŸŒ
Narkive
comp.soft-sys.matlab.narkive.com โ€บ AxjSCvrQ โ€บ cellfun-for-function-with-multiple-input-arguments
cellfun for function with multiple input arguments
Say, for example, I would like to replace every occurance of char 'a' with another char 'b' for each element of a cell array, so I created the below function: function newstr = replacestr(oldstr, achar, bchar) acharidx = findstr(oldstr, achar); newstr = oldstr; newstr(acharidx)=bchar and then in the main function, I used this to apply it on a cell array oldstrcell to replace 'a' occurance in each element of oldstrcell with 'b': newstr = cellfind(@replacestr, oldstrcell, 'a', 'b') but Matlab didn't work for above. Can anyone suggest how to do this? Thanks. ... Permalink You could use cellfun to do this, for example given: A = {'aappttaa','aatteeraff','sresahha'} % Method 1 C = cellfun(@(x) strrep(x,'a','b'),A,'Un',0) % Method 2 D = cellfun(@strrep,A,repmat({'a'},size(A)),repmat({'b'},size(A)),'Un',0) But why use cellfun when strrep would work just as well?
Find elsewhere
๐ŸŒ
Stack Overflow
stackoverflow.com โ€บ questions โ€บ 24414953 โ€บ how-to-evaluate-multiple-arguments-and-get-multiple-outputs-with-cellfun-in-matl
How to evaluate multiple arguments and get multiple outputs with cellfun in MATLAB - Stack Overflow
May 24, 2017 - Suposse the next two variables: A={[];[1 2];[3]}; B={[10 20 30];[40 50 60];[70 80 90]}; I need to get C1 and C2, who are: C1={[];[40 50];[90]}; % Corresponding value B(A), like B{2,1}([1 2])=[40...
๐ŸŒ
Rip Tutorial
riptutorial.com โ€บ useful functions that operate on cells and arrays
MATLAB Language Tutorial => Useful functions that operate on cells...
mydirnames = cellfun(@(x) x(1:end-4), mydirlist, 'UniformOutput', false) mydirnames = 'mymatfile1' 'mymatfile10' 'mymatfile2' 'mymatfile3' 'mymatfile4' 'mymatfile5' 'mymatfile6' 'mymatfile7' 'mymatfile8' 'mymatfile9'
๐ŸŒ
MathWorks
mathworks.com โ€บ matlabcentral โ€บ answers โ€บ 53724-using-multiple-functions-in-cellfun
Using multiple functions in cellfun - MATLAB Answers - MATLAB Central
November 14, 2012 - Using multiple functions in cellfun. Learn more about cellfun, cellfun example, multiple functions MATLAB
Top answer
1 of 2
2

To do this very fast, do not use either cellfun or str2double. Some possibilities:

strjoin with sscanf

Use strjoin to combine the strings in cell array x into a single long space-delimited string, which can then be parsed very quickly with sscanf:

sscanf(strjoin(reshape(x,1,[])),'%f')

Note the reshape is included to guarantee the cell array is a row, as required by strjoin. A simple permute (.') could be used if you know x is a column, or nothing if x is already a row.

vertcat (or str2mat) with sscanf

Instead of strjoin, form a virtual comma-separated list of strings with x{:} and vertically concatenate them with vertcat (if each string has the same number of characters). Transpose this 2D character array and sscanf can again parse it quickly in a single shot:

sscanf(vertcat(x{:})','%f');

Or if the number of characters varies from string to string, you can use str2mat, which creates a space-padded 2D character array that sscanf also happily reads:

sscanf(str2mat(x)','%f');

test

Create a cell array of string representations of 10,000 random numbers:

>> x = sprintfc('%f',rand(1e4,1));

Note the use of the undocumented sprintfc to print to cells.

Reference methods:

>> tic; d0 = str2double(x); toc
Elapsed time is 0.302148 seconds.
>> tic; d1 = cellfun(@(x) sscanf(x,'%f'),x); toc
Elapsed time is 0.277386 seconds.
>> isequal(d0,d1)
ans =
     1

strjoin and vertcat:

>> tic; d2 = sscanf(strjoin(reshape(x,1,[])),'%f'); toc
Elapsed time is 0.068129 seconds.
>> isequal(d0,d2)
ans =
     1
>> tic; d3 = sscanf(vertcat(x{:}).','%f'); toc
Elapsed time is 0.024312 seconds.
>> isequal(d0,d3)
ans =
     1
>> tic; d4 = sscanf(str2mat(x).','%f'); toc
Elapsed time is 0.011917 seconds.
>> isequal(d0,d4)
ans =
     1

Note: these numbers are ballpark as then should be run over multiple iterations inside of a script or function, but all code is warmed. Try them out.

2 of 2
2

How about a wrapper for the sscanf?

myWrapper = @(x) sscanf(x, '%f')
x={'0.17106'; '2.11462'; '4.13938'; '6.24203'}
cellfun(myWrapper,x)
str2double(x)
๐ŸŒ
MathWorks
mathworks.com โ€บ matlabcentral โ€บ answers โ€บ 482626-multiple-variables-into-a-cellfun
multiple variables into a cellfun - MATLAB Answers - MATLAB Central
September 28, 2019 - for j = 1:size(A,1) i = cellfun(@(x) isequal(x, [A{j}]), C); end Objective: get rid of the loop I have the following problem: A is an cell array witch consist of cells that are 1xn double , wh...
๐ŸŒ
Octave
octave.sourceforge.io โ€บ octave โ€บ function โ€บ cellfun.html
Function Reference: cellfun - Octave Forge - SourceForge
Input arguments that are singleton (1x1) cells will be automatically expanded to the size of the other arguments. If the parameter "UniformOutput" is set to true (the default), then the function must return scalars which will be concatenated into the return array(s). If "UniformOutput" is false, ...