Info
This question is closed. Reopen it to edit or answer.
How to use cellfun with a function that has multiple arguments?
1 view (last 30 days)
Show older comments
Hi,
I have the function dfaedit_2 which takes three arguments:
H = dfaedit_2(0,0,0)
Now, I want to run this fucntion on every cell in my cell array p_windows.mat using
cellfun(@dfaedit_2, C).
My question is how would I write this to input all the arguments needed for dfaedit_2?
Thank you!
1 Comment
Stephen23
on 26 Jan 2022
Edited: Stephen23
on 26 Jan 2022
"I have the function dfaedit_2 which takes three arguments: "
Actually your MAIN function takes no arguments at all. These are the first six lines of your file:
function main
file_name = 'p_windows.mat';
H = dfaedit(file_name,1,1,1)
end
function [H]=dfaedit(file_name,plot_flag, outfile_flag, out_command_flag)
...
"I want to run this fucntion on every cell in my cell array p_windows.mat"
A cell array is an array in the MATLAB workspace. A .mat file is a binary filed saved on a harddrive. Not the same thing.
"How to use cellfun with a function that has multiple arguments?"
Simpy ensure that you provide the function with its required inputs, e.g.:
fnh = @(a,b) sprintf('%s %s',a,b);
C1 = {'cat','hello'};
C2 = {'hat','world'};
cellfun(fnh,C1,C2,'uni',0)
Answers (0)
This question is closed.
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!