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

pass a matrix or vector to function handle in Matlab

everyone! I've got a problem when using function handle in Matlab. suppose I get a function handle of a transform matrix, say Tf = @(alpha)reshape([cos(alpha),-sin(alpha),sin(alpha),cos(alpha)],[2,2]); and I have a alpha vector alpha_list =…
hyharry
  • 11
  • 4
1
vote
1 answer

Function handle as a property of a class - Matlab

I define a class CellArrayHandle whose only property is a cell array of function handles: classdef CellArrayHandle < handle properties cel % cell array of function handles end end Suppose myHandle is an object of…
Frank
  • 11
  • 2
1
vote
1 answer

I am having trouble creating function handles. I want to embed a maximizing function within a minimizing function

The following code won't work, but this is the idea I'm trying to get at. c = @(x)constraints; %this is where I would initialize sum as 0 but not sure how... for i = 1:length(c) sum = @(x)(sum(x) +…
1
vote
1 answer

MATLAB: Pass class function handle to ode45()?

I have a class function that uses ODE45 to solve some equations. I have another, private class function that represents the odefunction that ODE45 needs to solve. However, I can't figure out how to pass a handle of the class's ode function to…
pcdangio
  • 294
  • 2
  • 13
1
vote
0 answers

Editing an array of function handle like A= @(x)[ ... ]

I have the following question. I created an array of function handle like A= @(x) [2*x; 3+x; 3-5*x; 4+7*x]; and I like to get a new array B=@(x)[3+x; 4+7*x] easily. Do you know how to get some components of function handle array? And I'd like to use…
Artj Chern
  • 11
  • 1
1
vote
1 answer

Vector inputs when converting symbolic expression to function handle

I have a symbolic ODE: syms x1 x2 cs ks ms t2 real xx=[x1 x2]; fun_sym=[xx(2); (cs/ms)*(xx(1)^2-1)*xx(2) - (ks/ms)*xx(1)]; I want to solve it using ODE function, but first I need to convert it into function…
student1
  • 860
  • 3
  • 11
  • 22
1
vote
2 answers

How to use a vector argument for a function generated by matlabFunction

When I run the following Matlab code: x=sym('x',[2 1]) func=x.'*x f=matlabFunction(func) x=rand(2,1) f(x(1),x(2)) % this works f(x) % but this gives an error I get an error: Error using…
1
vote
1 answer

Dynamically generate function for use in function handle

I'd like to dynamically construct a function that can then be referred to with a function handle for later use in Matlab functions such as integral(fun,a,b). As an example imagine a function with terms: (x-A)/(D-A) * (x-B)/(D-B) * (x-C)/(D-C) where…
Josh
  • 13
  • 3
1
vote
1 answer

Passing function name as argument in MATLAB

I know this question is already asked and answered here But I cannot make it work. I have a simple function f1 : function out = f1(x) out = x^2 + 5; end and I want to have a "delegate" function that takes the function name as input. Below you can…
jeff
  • 13,055
  • 29
  • 78
  • 136
1
vote
1 answer

Calling separate functions in Matlab

I'm trying to call a a function that allows the user to input an equation of their choosing, and then use a separate function to approximate it using the trapezoidal rule in numerical analysis. Here's my code for the user input equation: …
Matt
  • 29
  • 1
  • 5
1
vote
1 answer

cumulative sum of a cell of function handles

I have a cell of function handles: f{1}=@(x)a1(x); f{2}=@(x)a2(x); ... f{N}=@(x)aN(x); N is a large number here. What is the most convenient way to perform cumulative sum on all these function handles? e.g. I want to have a cell of new function g{}…
Void
  • 153
  • 4
  • 12
1
vote
1 answer

Apply Function Handle to Multiple Input Arguments

I have a matrix and a vector in MATLAB defined: A=rand(3); x=rand(3,1); And a function that takes these types of input arguments: b = MacVecProd(A,x); However, I'd like to use this function's function handle in order to apply it to my values. I…
geofflittle
  • 437
  • 1
  • 3
  • 14
1
vote
1 answer

How to generate multiple state spaces from arrays in MATLAB

I would like to ask how to create multiple state-spaces from arrays. Input is: A1toA100 (100xn double) B1toB100 (100xp double) C1toC100 (100xn double) D1toD100 (100xp double) Example: A1toA10 = -0.5909 -0.4178 -0.3412 -0.2954 …
PeV
  • 113
  • 3
1
vote
1 answer

how to get tag of a clicked rectangle in matlab

I have a set of rectangles in a figure. I'm tagging them by a rect_tag index, and I want to get an array (or cell array) which has the tags of clicked rectangles. The rectangles are generated by: for i_nf=1:nRects rect_tag = ['rectangle_num_'…
mousomer
  • 2,632
  • 2
  • 24
  • 25
1
vote
2 answers

Matrix multiplication of a Array Cell of function handle

I have built up a cell array of function_ handles like below: B = {@(x) x(1)+x(2)^2 @(x) x(1)-2*x(2)} Assume A = [1 2; 3 4]. I need to perform a matrix multiplication like A*B to have a cell array as A*B = {@(x) x(1)+x(2)^2 + 2*(x(1)-2*x(2))…
user2745742
  • 65
  • 1
  • 4