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
1
vote
2 answers

Adding an arbitrary number of functions into a function handle MATLAB

I'm trying to generate .bmp graphics in MATLAB and I'm having trouble summing functions together. I'm designing my function such that given an arbitrary set of inputs, my function will add an arbitrary number of functions together and output a…
0
votes
1 answer

How to create parametrized matrix

I would like to create parametrized matrix with given relationship between arguments like this: B= @(A) [1*A(1), 2*A(2), 3*A(3), 4*A(4)]; But matrix is huge and cannot be created by constant expression like this. I need something like this: for…
Ales100
  • 153
  • 1
  • 8
0
votes
0 answers

How can I call files within a functions folder to require the path and pass in the client?

I'm coding a discord bot and I have commands in a command folder and events in an event folder, however the command handler and event handler are in a functions folder. However, on my main script I need to call upon the functions folder so that it…
0
votes
0 answers

How to use the integral function with function handles in Matlab

My task is to calculate the area between two curves (named 'water retention curves'). I tried to calculate this area with the build-in 'integral' function (see line 32), but the command window tells me the output of the function must be of the same…
Haïko
  • 11
  • 1
0
votes
0 answers

MATLAB function handle with a matrix in a particular formation

This question arises from a matlab community add-on function "general simulated annealing algorithm". The function needs a 'loss function' which is required to be minimized. The loss function is a function handle, for example the camel function…
user835469
  • 11
  • 2
0
votes
1 answer

Vectorising a function array in Matlab

My generic problem is illustrated by the following example: f=@(x,y) cos(x.*y); Yvalues = linspace(0,1,50); W = @(x) f(x,Yvalues); which works fine if I only want to evaluate W at one point at a time. For instance: norm(W(pi/3)-f(pi/3,Yvalues)) ans…
alext87
  • 371
  • 5
  • 12
0
votes
1 answer

How can I pass a vector to a function handle of the same size , so that it automatically takes the first input as the first variable and so on? MATLAB

Assume I have a vector A=[a1 a2 a3 ... an], and a defined function handle f=@(x1,x2,x3,..,xn), how can I input the vector to the function handle without explicitly writing f(A(1),A(2),...,A(n))? The code I am writing gives me different n for…
HousamKak
  • 23
  • 3
0
votes
2 answers

How to assign indexes to a function handle?

I'm trying to approximate the integral of the functions "fun_1" and "fun_2" over the given region. In the case of one single "f" it seems ok. But I want to use a vector "f" instead of a single value to have a vector of "TL" values. I don't know how…
0
votes
2 answers

How to create a function handle of a function with both new input parameters and output parameters from previous call in Matlab?

I am trying to create a function and a function handle of the said function where the function takes in output parameters from the previous call and new input parameters and calculates the gradient in the function as given in the toy example shown…
shunyo
  • 1,277
  • 15
  • 32
0
votes
1 answer

Event Listeners and Global Variables that are defined = "Uncaught TypeError is not a function" when set as function before invoking

I ran into an interesting issue when defining a global variable (as null in this case), and having a function change that global variable to a callback that was passed to that function---then trying to invoke the global variable (which is now the…
0
votes
2 answers

handle function Matlab

I'm starting to use functions handles in Matlab and I have a question, what Matlab computes when I do: y = (0:.1:1)'; fun = @(x) x(1) + x(2).^2 + exp(x(3)*y) and what Matlab computes when I do: fun = @(x) x + x.^2 + exp(x*y) Because I'm evaluating…
JCV
  • 447
  • 1
  • 5
  • 15
0
votes
1 answer

MATLAB | f=@(x) function handle with range + conv

I have these functions with the code that aims to plot the two signals - x(t) and h(t) - alongside their time range then find the convolution of the two signals. x=@(t)…
A10AIO
  • 3
  • 1
0
votes
1 answer

Matlab function handle optimizing

I have a function handle in Matlab like this fhandle = @(A) max(1-2*A,0).*(2*A.^5+2*A + 1) Where A is typically a matrix. I perform this quite a few times and it is slowing down the computation. It is possible to keep it as a function handle (so I…
alext87
  • 371
  • 5
  • 12
0
votes
1 answer

Can someone please explain how the function handle in this Matlab code works

Can someone please explain how the function handle in this code works! Currently, the code is not jumping to the function and I'm trying to fix it. And can You please explain, how can I write the same code without using the function handle. This…
0
votes
1 answer

Order of calculation for multiple successive division operations in a single term

Why does this function handle in Matlab g = @(x)(4*x^5-A)/5/x^4; correspond to g(x) = (4x^5-A)/5x^4 and not to (4x^5-A)/(5/x^4)?