Help needed in passing a function as a parameter in another function
1 回表示 (過去 30 日間)
古いコメントを表示
Hi,
I have a function named sample as follows:
function x= sample(*func_f*)
It takes in input another function which is to be processed. Now in another matlab file, I access all the files in one directory (which are functions) and i need to pass them into this sample function.
I use the following approach for this:
T=dir(['./' fcts_folder '/*.m']);
funcname=T(i).name(1:end-2);
x= sample( str2func(funcname) )
But this gives me an error : Undefined function 'sample' for input arguments of type 'function_handle'.
Any ideas how I should go about this?
2 件のコメント
回答 (1 件)
Rob Campbell
2012 年 6 月 13 日
"no I am in the directory where sample.m is and the functions that I need to pass are in the fcts folder in a directory inside the directory where sample.m is."
That would likely be your problem. The functions in the fcts directory need to be in your path. Add them with addpath or pathtool
参考
カテゴリ
Help Center および File Exchange で Search Path についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!