Info
この質問は閉じられています。 編集または回答するには再度開いてください。
How to use cellfun with a function that has multiple arguments?
1 回表示 (過去 30 日間)
古いコメントを表示
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 件のコメント
Stephen23
2022 年 1 月 26 日
編集済み: Stephen23
2022 年 1 月 26 日
"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)
回答 (0 件)
この質問は閉じられています。
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!