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
0 answers

MATLAB - Newton's Method to solve a system of nonlinear equations

I'm trying to write a function that uses Newton's Method to solve a system of nonlinear equations Function: [roots, count, resids, history] = Newtons(func,x0,tol) with the following inputs and outputs. I'm struggling with creating the function…
Nick Stephen
  • 55
  • 1
  • 5
1
vote
1 answer

recursive function handle in MATLAB

Assume the following: u=[1 2 3]; W_in=[4 5 6]'; W=[1 2 3;4 5 6;7 8 9]; x=zeros(3,4); %initialization x(:,1)=[1 2 3]'; How can I create a function handle such that: x(:,i)=@(gamma) (1-gamma)*x(:,i-1)+gamma*(W*x(:,i-1)+W_in*u(i-1)) where gamma is…
law_light
  • 59
  • 3
1
vote
1 answer

function handle is not converting - matlab

I'm getting these error: Conversion to function_handle from double is not possible. Already searched about it and tried to change my code but without sucess. Could u help? Thanks A=[99.23;100.05;91;107.71;104.1]; B=[3441 3441 301720.5;68750…
1
vote
1 answer

Matlab: function handle in cell array with undefined operators

When I try to run this code I get the following error: "Undefined operator '.*' for input arguments of type 'cell'." My goal here is to build an array (cell array since I'm working with function handles) via a for loop and take the integral of each…
1
vote
1 answer

How to get the number of outputs from a handle to a method in Matlab?

You can call methods of an object using function handles. Example: classdef foo methods function value=foofun(this) value=1; end end end and then fun=@foofun; fun(foo); The handle is just a string I guess, and it doesn't bother…
Memto
  • 15
  • 5
1
vote
1 answer

How to correctly create function handle for multi-variable piecewise function?

I want to create a function_handle using an anonymous function for the following: f(x,y) = 1, if 2 <= x <= 3 and y = 1, f(x,y) = 0, otherwise I thought I could just do: f @(x,y) 1.*((x >= 2) && (x <= 3) & (y == 1)); When I try to evaluate this…
1
vote
1 answer

Transform equal function handles to other equal function handles

Minimalistic Example: classdef MyClass properties arr handArr end properties(Dependent) rowAcc colAcc end methods function obj = MyClass(arr, handRow, handCol) obj.arr = arr; obj.handArr{1} = handRow; if…
Omer Rosler
  • 237
  • 1
  • 10
1
vote
1 answer

Simulate 'this' pointer in matlab

I have a class that encapsulates access to an array in a wierd way; The class constructor takes a function handle which is some kind of transformation of indexes before passing them to the array classdef MyClass properties arr …
Omer Rosler
  • 237
  • 1
  • 10
1
vote
1 answer

Function handle using `set` function MATLAB

I'm working at GUI in MATLAB application. I use uitable object. Then I find interesting undocumented feature how to sort it's data, select whole row and etc. I do this way: % create jhandle to my uitable object juiTable =…
Mikhail_Sam
  • 10,602
  • 11
  • 66
  • 102
1
vote
1 answer

iterating over quadgk with multiple parameters

I am trying to evaluate a numerical integration using quadgk, as I am not expert in matlab, I am having a hard time to get the following code to work. I have matrix g(i,j) where I am evaluating an integral over parameter phi for each element of g.…
setareh
  • 13
  • 5
1
vote
1 answer

Passing function handle as input for mex for Matlab

I'm recently working on finite element method with MATLAB I tried to optimize my code in MATLAB. While searching, I found that matrix assembling could be accelerated by using mex function. While porting my "PoissonAssembler.m" to mex function, I…
Dohyun
  • 642
  • 4
  • 15
1
vote
2 answers

Passing sum function matlab and add column wise sum

Is it possible to pass the sum function and declare how to summarize the values? So column or row wise? Like I call the function without passing: y = sum(x,2); I want to call an Aggregation function like this, but operate in the rows: Output =…
1
vote
0 answers

Adding function handles

I have in MATLAB a cell array C containing containing n function handles @(t). I also have a vector x_star containing n constants. I am now trying to make a new function handle consisting of the function on location i in the cell array times the…
some_name
  • 389
  • 3
  • 17
1
vote
1 answer

Multipy function handles matlab

I need to multipy two function handles and get function handle as a result. e.g. : u = @(x) x + 2; v = @(x) 2*x + 1; y = u * g; How to do this?
borapop
  • 23
  • 4
1
vote
2 answers

Is there a way to combine multiple functions for plotting without retyping them in MATLAB?

In the classes I'm currently taking, there is a considerable amount of plotting going on. To speed things up, I started using fplot instead of plot. Now I'm wondering if there's a way to combine two functions together without retyping…
Gryph
  • 13
  • 3