Help needed in passing a function as a parameter in another function

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

Did you cd() out of the directory that sample.m is in ?
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.

댓글을 달려면 로그인하십시오.

답변 (1개)

Rob Campbell
Rob Campbell 2012년 6월 13일

0 개 추천

"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

댓글 수: 1

No the problem isn't this. This thing I have taken care of, checking files in a subdirectory.
I solved the problem. I wasn't making an object of the class in which this sample function was. Once I made the object and then called the function it worked.
Thanks a lot for your help though ! I appreciate it.

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Search Path에 대해 자세히 알아보기

질문:

2012년 6월 12일

Community Treasure Hunt

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

Start Hunting!

Translated by