Sign in

username:

password:



Not a member?

Search matlab



Search tips

Subscribe to matlab



matlab by Keywords

Atanh | Autocorrelation | Bandpass Filter | C++ | Conv | Database | Deconv | Excel | FFT | Filter | Filtering | FIR | Fourier Transfrom | FSK | Gaussian Noise | Haykin | IFFT | Image | Java | LFSR | LMS | LPC | MEX | OFDM | QPSK | Radix | Random | Sampling | Segmentation | Simulink | Visual Basic | Waveform | Wavelet

Ads

Discussion Groups

Discussion Groups | Matlab DSP | How to call a function as an argument of another function

Technical discussion about Matlab and issues related to Digital Signal Processing.

  

Post a new Thread

How to call a function as an argument of another function - "Ye, Xiaoxia" - Mar 23 15:03:41 2008



Dear all,

I have a question about how to call a function as an argument of another function. 

For example, first I have "fun1" as 

function a=fun1(x,y)
a=x*y;

then, I want to write "fun2" which calls "fun1" as an argument as

fun2(x,y,fun1);

function a=fun2(x,y,f)
a=f(x,y);

Apparently, above codes do not work. So how could I write "fun2" correctly?? Thanks
in advance!!
 
Best,

Xiaoxia Ye



(You need to be a member of matlab -- send a blank email to matlab-subscribe@yahoogroups.com )

Re: How to call a function as an argument of another function - Mudasser Naseer - Mar 24 8:29:46 2008

            

Hi Xiaoxia

Run the following code and see the results, I hope it will solve your problem.

function a = main()
x = 3;
y = 4;
a2 = func2(x,y,fun1(x,y));
disp(a2);
end

function b = func2(x,y,f)
b = x+y+f;
end

function a = fun1(x,y)
a = x*y;
end

Mudasser

--- On Sun, 3/23/08, Ye, Xiaoxia <wisesummerye@yahoo.com> wrote:
From: Ye, Xiaoxia <wisesummerye@yahoo.com>
Subject: [matlab] How to call a function as an argument of another function
To: matlab@yahoogroups.com
Date: Sunday, March 23, 2008, 1:26 AM

Dear all,

I have a question about how to call a function as an argument of another function.

For example, first I have "fun1" as

function a=fun1(x,y)
a=x*y;

then, I want to write "fun2" which calls "fun1" as an argument as

fun2(x,y,fun1) ;

function a=fun2(x,y,f)
a=f(x,y);

Apparently, above codes do not work. So how could I write "fun2" correctly?? Thanks in advance!!

Best,

Xiaoxia Ye



(You need to be a member of matlab -- send a blank email to matlab-subscribe@yahoogroups.com )