Questions tagged [function-handle]

In Matlab, a function handle is a mechanism provided to allow for indirect calling of a function. Serves like a "pointer to function"

A function handle is a value that provides a means of calling a function indirectly.

159 questions
2
votes
2 answers

How to get a handle to an overriden built-in function?

On my Matlab path there's a custom zeros function. I want to store a handle to the built-in zeros in a variable. How can I do that? Thought about @(varargin)builtin('zeros',varargin{:}), but this would probably slow down the operation due to the…
Michael Litvin
  • 3,976
  • 1
  • 34
  • 40
2
votes
1 answer

Deciphering a Function Handle Solution Found in http://stackoverflow.com/a/13135833/560821

So... I can understand matlab function handles and its purposes. But sometimes, when it gets too cryptic, I require help in further elaborating it. Take this example from the default MATLAB documentation, say: f = @(x)x.^3-2*x-5; I can also…
Denz Choe
  • 81
  • 2
  • 7
2
votes
2 answers

Passing a function as an argument into another function won't compile without using quotes ''?

When I pass a function (let's call it f) into my Base function , the Base function doesn't recognize the f function , without using '' quotes , here's the code : function y = test(a, b, n ,f) if ( rem(n,2) ~= 0 ) error ( 'n is not even'…
JAN
  • 21,236
  • 66
  • 181
  • 318
1
vote
3 answers

MatLab recursion error (beginner)

Ok. So i've got two function in MatLab that are calling each other. Riemann.m function I = Riemann(f, dx, a, b) x = a:dx:b; fx = f(x).*dx; I = sum(fx); and myfunc.m function f = myfunc(x) f = sin(1./x); for n=1:100 I =…
Matti Lyra
  • 12,828
  • 8
  • 49
  • 67
1
vote
1 answer

Julia Function Handle

I want to perform a function_handle in Julia as MATLAB does. Suppose I create a function in MATLAB like this: fn = @(b, x) process(b, x, @trans); And then I put this function as input of another function function m = AnotherFunc(m, l, func) where m…
sssss
  • 21
  • 2
1
vote
1 answer

How to set up an anonymous function to take vector input in Octave?

I would like to define an anonymous function that takes a vector, but I am unable to achieve that unless every element in the vector is specified: Data = [ X11 X12; X21 X22]; Iteration #1: V -> [X11 X12] (desired row of values to be passed into…
broccolee
  • 11
  • 2
1
vote
2 answers

function handle to nested function not working for some values of parameter

This function is supposed to return a function handle to the nested function inside, but if the variable x is set to a negative value in the outer function, it doesn't work. The inner nested function is just a constant function returning the value…
overglow
  • 13
  • 4
1
vote
1 answer

Passing matrix element as function handle

I have applied inverse laplace transform to a matrix and now it is a function of t. My goal is to substitute t value and get the result matrix. I intended this code to be pretty straight foward but I'm not getting it work. This is what I…
Rezik
  • 31
  • 5
1
vote
2 answers

Error using fzero in Matlab: Undefined function or method 'det' for input arguments of type 'function_handle'

I have the same kind of problem described in this topic: Using fzero: Undefined function or method 'isfinite' for input arguments of type 'sym' Their answers really helped me, but I am still stuck. I also have to find the zeros of a function of w,…
Rambaldi
  • 33
  • 1
  • 6
1
vote
2 answers

How do I call a function handle with an vector rather than a list of arguments?

I was wondering how to call a function handle with an vector of inputs - rather than the list of aguments. So if I have a function handle which is defined: (I guess it will be clear that I am working on fitting functions here) fitFunctionHandle =…
JPH
  • 1,224
  • 2
  • 14
  • 21
1
vote
1 answer

why do i get fminsearch undefined function error

I'm trying to optimize a function with 2 inputs. Trying to use fminsearch but it keeps saying undefined function or variable although it is already defined. I have already defined the function in a separate script that is in the same directory with…
1
vote
1 answer

Make a MATLAB function explicit

I am using a toolbox in MATLAB and I'm not ready to make any change to the functions within it. Let's say that it has a function f = @(x,l) g(x)*h(l) I want to call f at different x but always the same l: l = 3; f2(x) = @(x) f(x,l); for…
Ludo M
  • 15
  • 4
1
vote
1 answer

MATLAB: Summing function handles

I'm trying to automatically create a function handle that is a sum of function handles. When I tried to do this manually, it worked: f1 = @(x) x(1); f2 = @(x) x(2); f3 = @(x) x(3); f = @(x) f1(x)+f2(x)+f3(x); But when I tried to do this…
1
vote
1 answer

I want to feed in a function handle into a matlab function I made

I am trying to feed a function handle into the function I created below. I'm not exactly sure how to do this. For example, how do I get: conjugate_gradient(@(y) ABC(y), column_vector, initial_guess) to not error? If I use matlab's pcg function in…
SomeDude
  • 17
  • 1
1
vote
1 answer

How to assign values to variables in a handle function?

This is simplified but take as an example the following MATLAB function handle: F = @(x)[x(1)-x(2);x(2)-x(3)] The system has of course has many solutions. Is it possible to obtain a solution for a function like this one after substituting at least…
ser
  • 13
  • 3