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 do I retain the number of arguments of a function handle when passing it to some other function in Matlab?

I am trying to write a function that takes a cell array of functions as an input and that outputs the same functions, but in a somewhat different format. Specifically, I want a row vector, of say length N, of functions fVec = [f1(x, y, z),…
Sam
  • 305
  • 1
  • 8
0
votes
1 answer

Creating function handle from two vectors to pass to an integral function in MATLAB

I'm not sure if I'm being thick here, but I'm not used to function handles etc. I am trying to find the integral of some raw accelerometer data i have, and was advised by a friend that using Simpsons might be the best way. So i found that MATLAB has…
Ross Hanna
  • 25
  • 4
0
votes
1 answer

Issue with using fplot on a symbolic expression

Here is an example where fplot doesn't plot…
Y. zeng
  • 121
  • 7
0
votes
1 answer

How to square the result of cfit?

I'm using MATLAB for some data analysis of experimentally collected data. After using the envelope and abs functions I'm using the fit function to get the equation I'm after, which I need to square then integrate. The code I have for getting the…
0
votes
1 answer

How to convrt 1x1 sym to function/expression?

Below you can find implemented Newton method. function y = NewtonRoot(Fun, DFun, Xest,Err, imax) %Fun - function %DFun- derivative of F %Xest - initial estimate of solution %Err - maximum error %y - solution %EXAMPLE:…
0
votes
0 answers

Array of function handle in matlab

Starting from the vector Psi_0 I define the propagated vector as Psi (t) = exp{-iHt} Psi_0, where H is the Adjacency matrix (but I think it is irrelevant to my problem here). I need to calculate 1/tau * int^tau_0 ||^2 dt I tried to do…
raskolnikov
  • 235
  • 1
  • 6
0
votes
1 answer

function handle in matlab

Hi~ I'm learning using shootig method to solve a differential equation with boundary condition. The problem is (from Sauer textbook): function z=F(s) a=0;b=1;yb=3; ydot=@(t,y) [y(2);4*y(1)]; [t,y]=ode45(ydot,[a,b],[1,s]); z=y(end,1)-yb; % end means…
Claire Sun
  • 23
  • 2
0
votes
1 answer

Using `lsqnonlin` with vector inputs

I have a question about using the lsqnonlin function. In my case I have two functions: f_1=@(t,x)sin(t+x.^2); f_2=@(t,x)cos(x.^2)+3.*t.^2; f = {f_1, f_2}; I want to find the values of the arguments t and x which would result in the least square…
0
votes
1 answer

Confusion about function handles in One vs. All Regression

I'm taking Andrew Ng's Machine Learning course on coursera, and I'm pretty confused as to why one particular example works in the One vs. All classification: function [all_theta] = oneVsAll(X, y, num_labels, lambda) %ONEVSALL trains multiple…
muZero
  • 948
  • 9
  • 22
0
votes
2 answers

Invoking a method defined into a running Figure

I have the following UIFigure: classdef gui < matlab.apps.AppBase ... function app = gui % Construct app end ... properties (Access = public) myFuncRef = @myFun end ... function myFun(app) % do something …
user3818252
0
votes
1 answer

Take product of function handles within a cell and then evaluate for given values in MATLAB

I have a cell of function handles and I would like to take the product of each row. I then want to evaluate the function handles within the cell for certain values. Example: Original cell: P{1,1} = @(x) x P{1,2} = @(y) y P{2,1} = @(x) x…
Buzz92
  • 9
  • 5
0
votes
0 answers

Finding global minimum of complicated nonlinear function within the range of Earth's surface (MATLAB)

I am struggling with finding the global (or at least local minimum) of nonlinear 3-variable function S(t,x,y) defined as following with MATLAB 2016b: Given function requires x_i, y_i, d_i, v as input variables and x, y, t are variables to be…
0
votes
1 answer

Error when passing arguments to function handles

Suppose we have the following function: function f=lorenz(t,x,a,b,c) % solve differential equation like this %dx/dt=a*(y-x) %dy/dt=-x*z+b*x-y %dz/dt=xy-c*z/3 f=zeros(3,1);% preallocate result f(1)=a*(x(2)-x(1)); …
user466534
0
votes
0 answers

How calculate integration of multiplying two-looped function in matlab

I have a function that changes by loop , as below f(x,y)=(i-1)*x+(j-1)*y g(x,y)=(i+1)*x+(j+1)*y The real function is more Complex than this, however/ I want to calculate the integration of f(x,y)*g(x,y) when i & j are changed by the loop. I want to…
mohammad
  • 1
  • 2
0
votes
2 answers

Get the handle of a member of a class that has no instantiation yet

This question is connected (but NOT duplicate) of this one. Consider that I am fairly new to C#. I would like, if possible, to take the handle of a member of an object that has not been instantiated jet, in order to use it later on. Following…
Vaaal88
  • 591
  • 1
  • 7
  • 25