0

I was just browsing through a code and I found the following line :

other_function(@(t)(xx(t,g)))

where other_function,xx are already defined functions and g is already defined.

Here is the code for xx

function [val]=xx(x,y)
val=x+y;
end;

SO now I am unable to understand the meaning of @(t)(xx(t,g))

Apoorv Jain
  • 125
  • 6
  • 1
    What happens in other_function? The handle of the function `xx` is passed to `other_function`. – Robert Seifert Sep 13 '18 at 12:49
  • 1
    It's used like this so you don't have to pass `g` into every `other_function` call. If `g` should always be input the same, then this syntax turns `xx` (a function of 2 inputs) into `other_function` (a function of 1 input with the same functionality as `xx`). – Wolfie Sep 13 '18 at 13:56

1 Answers1

0

It is a function handle. It is useful to pass functions as parameters. You can find more in the MATLAB documentation

Just an example: suppose you have a simple function

function y = computeSquare(x)
y = x.^2; 
end

than you can compute an integral in this way:

q = integral(@computeSquare,0,1);

In your example: other_function declares as an input parameter a function t and another parameter called g.

Lorelorelore
  • 3,335
  • 8
  • 29
  • 40