Info

La pregunta está cerrada. Vuélvala a abrir para editarla o responderla.

How to use cellfun with a function that has multiple arguments?

2 visualizaciones (últimos 30 días)
lil brain
lil brain el 26 de En. de 2022
Cerrada: Stephen23 el 26 de En. de 2022
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 comentario
Stephen23
Stephen23 el 26 de En. de 2022
Editada: Stephen23 el 26 de En. de 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)
ans = 1×2 cell array
{'cat hat'} {'hello world'}

Respuestas (0)

La pregunta está cerrada.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by