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
0
votes
1 answer

How to specify function signature for function handles in MATLAB code generation?

I want to compile a MEX from a function that has the following code (MATLAB R2015a): function r = MyFunc(x,type) ind = randi(numel(x), 1); getInd = @getIndFixed; if strcmpi(type, 'random') ind = numel(x); getInd =…
Girardi
  • 2,734
  • 3
  • 35
  • 50
0
votes
0 answers

Using handles to nested function for GUI callbacks in Octave

I am trying to develop a GUI in Octave (4.0.1, using the GUI version) with the code as follows: Main GUI function Function to create figure & various uicontrol Callback function for uicontrol #1 Callback function for uicontrol #2 Callback…
am304
  • 13,758
  • 2
  • 22
  • 40
0
votes
1 answer

Creating a function handle for each element in a vector (Matlab)

I have a following issue. I am trying to create a function handle, which is a vector. In particular, I have something like this EQ0 = @(W) m1.^2*(exp(W))-m2.^2 where m1 and m2 are the vectors of the same dimension. So, for each m1(i) and m2(i)…
Natalia K
  • 3
  • 3
0
votes
1 answer

How to assign one function to different UI controls in GUIDE?

I have a set of push-buttons in a figure designed in GUIDE and I want to assign one single function as their callback functions. But there is no combo-box to choose my function from in the property inspector, and when I select all buttons and click…
saastn
  • 5,717
  • 8
  • 47
  • 78
0
votes
1 answer

MATLAB function handles and parameters

When I type help gmres in MATLAB I get the following example: n = 21; A = gallery('wilk',n); b = sum(A,2); tol = 1e-12; maxit = 15; x1 = gmres(@(x)afun(x,n),b,10,tol,maxit,@(x)mfun(x,n)); where the two functions are: function y = afun(x,n) y…
System
  • 241
  • 2
  • 4
  • 13
0
votes
1 answer

Trouble understanding an anonymous function

I do not understand the following code: rect2rng = @(pos,len)ceil(pos):(ceil(pos)+len-1); From the the previous link: BoundingBox Matlab
0
votes
1 answer

Simplify fit function in MATLAB with handle

I want to fit some data with MATLAB but my fit-function is pretty large and I just want to put it into pieces of functions. At first I just tried it like p1_prime = @(x,p) ... p2_prime = @(x,p) ... Then I put it into my model function mod =…
0
votes
1 answer

MATLAB ERROR Feval requires a function handle as the first argument

I have this code (*) and when I do: »syms x »newton_raphson({((5400.*(1 + x)*0^360) - (1450000.*x.*(1 + x).^360))}, diff(((5400.*(1 + x)*0^360) - (1450000.*x.*(1 + x).^360)),1), 0.001, eps, 5, 0.1) this error appears: Error using feval …
0
votes
1 answer

How to use pcg with a function in MATLAB

I am going to solve an inverse problem, AX=b, using conjugate gradient method in MATLAB. I want to use pcg function in MATLAB and as I know instead of matrix A I can use a function. I have a function for example afun which has some entries. In the…
0
votes
1 answer

Operations with function handle in matlab

Could you please help me with the following issue: I have the following function handle: r1 = @(lambda) b + lambda*(r - b); % r and b are vectors of return data I want to find the optimal lambdas that set me a mean function to zero, for a given set…
Astrid
  • 43
  • 1
  • 2
  • 7
0
votes
1 answer

Define a function with a function handler as argument

Is it possible to define a function with a function handler as an argument in Matlab? I've tried with function x = name(@f,gh) but I get an error message stating Invalid syntax at '@'.
0
votes
1 answer

Passing C++ callbacks to matlab engine as function handles without using mex

My project is in C++. I want to use matlab optimization nonlinsq through matlab engine by "eval". I want to pass a function I wrote in C++ in the format of void func(int nlhs, mxArray *plhs[], int nrhs, mxArray *prhs[]) to matlab as a…
user2070148
  • 45
  • 11
0
votes
2 answers

Evaluating a constant anonymous function in MATLAB

In Matlab, I generally do things such as f = @(x) x.^2; xx = 0:.1:1; ff = f(xx); So that f is a function handle and both xx and ff are 1x11 vectors. However, if for some reason I need to define my function handle f like this f = @(x) 1; and do…
Tom
  • 103
  • 1
0
votes
1 answer

Error with function handles in a loop (Matlab)

I am trying to run a loop which includes a function handle. The code works well if I use any specific value for n. However, when I try to run the code within a loop it gives the error: Nonscalar arrays of function handles are not allowed; use…
sets
  • 169
  • 7
0
votes
1 answer

Generating a trinomial tree in matlab

what I am trying to do is to generate a series of vectors that emulate the structure of a non-recombining trinomial tree. Here is my code: function Trinomial_tree S{1}(1) = 100; w{1} = 1.4; w{2} = 1.1; w{3} = 0.7; T = 2; %Compiling the w's into a…
user5128359