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

Is there a better way to use cellfun with arguments? and is it better than for-loop?
Is there a better way to use cellfun with... Learn more about cellfun, function, arguments MATLAB More on mathworks.com
🌐 mathworks.com
2
0
September 8, 2021
cellfun for function with multiple inputs
I want to apply a function to every cell within a cell array, so using cellfun seems the logical way to go. But the function requires two inputs, one would be the cell array,A, and the other is B, ... More on mathworks.com
🌐 mathworks.com
1
3
January 5, 2018
matlab - How to apply cellfun (or arrayfun or structfun) with constant extra input arguments? - Stack Overflow
I want to apply a function to each element of a cell array -- so I have cellfun for that. However, the function takes two extra arguments (a string and a vector), which I want to keep constant for ... More on stackoverflow.com
🌐 stackoverflow.com
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 - B is fixed in my example (i.e. it should be in the workspace at the point the function is definied). a is a placeholder for a variable argument which will be supplied later. 'Later' in your case means in the cellfun statement, where each element ...
🌐
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
🌐
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' Again, as an output is not a regular vector of numbers, an output must be saved in a cell variable. In the example below, I combine two functions in one and return only a list of file names without an extension:
🌐
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.

🌐
Octave
octave.sourceforge.io › octave › function › cellfun.html
Function Reference: cellfun - Octave Forge - SourceForge
function [a, b] = twoouts (x) a = x; b = x*x; endfunction [aa, bb] = cellfun (@twoouts, {1, 2, 3}) ⇒ aa = 1 2 3 bb = 1 4 9 · Note that per default the output argument(s) are arrays of the same size as the input arguments.
🌐
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
🌐
Mit
lost-contact.mit.edu › afs › inf.ed.ac.uk › group › teaching › matlab-help › R2016b › matlab › ref › cellfun.html
cellfun
Name is the argument name and Value is the corresponding value. Name must appear inside single quotes (' '). You can specify several name and value pair arguments in any order as Name1,Value1,...,NameN,ValueN. Compute the mean of each vector in cell array C. C = {1:10, [2; 4; 6], []}; averages ...
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 › 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 - So I would suggest calling your function in a loop instead of hacking something together with cellfun. Sign in to comment. ... 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.