function-handle

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

喜欢而已 提交于 2019-12-11 01:54:40
问题 I am fairly new to C#. What I want to do may seem convoluted. Let's start by saying that I want to take a handle of some functions in order to execute them later on. I know that I can achieve this in the following way: List<Action> list = new List<Action>(); list.Add( () => instanceA.MethodX(paramM) ); list.Add( () => instanceA.MethodY(paramN, ...) ); for(Action a in list) { a(); } However, what if the instanceA object does not exists yet, but I know it will exists when I call the

Converting Cell array of function handle into a single array of function handle

牧云@^-^@ 提交于 2019-12-10 18:15:02
问题 I need to build up a vector of non-linear equations to be used in fsolve to solve it. But I should make each element of the vector in each loop iteration. How can I make up such a vector? In fact, I can not use cell array. How can I convert a cell array like {@(x) x(1)+x(2)^2; @(x) x(1)-2*(x(2))} into an array like @(x) [ x(1)+x(2)^2 ; x(1)-2*(x(2))] ? Because I want to use fsolve to solve the system of non-linear equations. 回答1: Use func2str to get the function definitions in string and use

How to get a handle to an overriden built-in function? [duplicate]

情到浓时终转凉″ 提交于 2019-12-09 07:11:18
问题 This question already has an answer here : How to unhide an overriden function? (1 answer) Closed 6 years ago . On my Matlab path there's a custom zeros function. I want to store a handle to the built-in zeros in a variable. How can I do that? Thought about @(varargin)builtin('zeros',varargin{:}) , but this would probably slow down the operation due to the string comparison. Also, I've noticed that it's possible to refer to diag as @numel\diag , but this doesn't seem to work with other built

How can I validate a function handle as an input argument?

[亡魂溺海] 提交于 2019-12-06 06:33:52
问题 I have a class that has a function handle as one of its properties . classdef MyClass properties hfun %function handle end methods function obj = Myclass(hfun,...) %PROBLEM: validate that the input argument hfun is the right kind of function if ~isa(hfun,'function_handle') || nargin(hfun)~=1 || nargout(hfun)~=1 error('hfun must be a function handle with 1 input and 1 output'); end obj.hfun = hfun; end end end I'd like to make sure that the input argument hfun is a function handle with 1 input

Calling matlab callback/function handle from Java

牧云@^-^@ 提交于 2019-12-06 02:57:44
问题 How do I pass a matlab function handle to a Java object and invoke it from within Java (that is, I want Java to tell matlab when it is ready with a calculation). I am trying to use the com.mathworks.jmi.Matlab class for evaluating Matlab expressions in the Java object, but I can't see how to 1) transfer the callback funcktion handle to Java, and 2) invoke it from Java possibly using the com.mathworks.jmi.Matlab class. Thanks, jakob 回答1: Hmm. Looks like JMI is one of those matlab internals

How can I validate a function handle as an input argument?

人走茶凉 提交于 2019-12-04 12:25:15
I have a class that has a function handle as one of its properties . classdef MyClass properties hfun %function handle end methods function obj = Myclass(hfun,...) %PROBLEM: validate that the input argument hfun is the right kind of function if ~isa(hfun,'function_handle') || nargin(hfun)~=1 || nargout(hfun)~=1 error('hfun must be a function handle with 1 input and 1 output'); end obj.hfun = hfun; end end end I'd like to make sure that the input argument hfun is a function handle with 1 input and 1 output, otherwise it should error. If I could get even more specific I'd like this function to

Calling matlab callback/function handle from Java

☆樱花仙子☆ 提交于 2019-12-04 05:39:51
How do I pass a matlab function handle to a Java object and invoke it from within Java (that is, I want Java to tell matlab when it is ready with a calculation). I am trying to use the com.mathworks.jmi.Matlab class for evaluating Matlab expressions in the Java object, but I can't see how to 1) transfer the callback funcktion handle to Java, and 2) invoke it from Java possibly using the com.mathworks.jmi.Matlab class. Thanks, jakob Hmm. Looks like JMI is one of those matlab internals things which may be subject to change in future versions. I found these online articles, not sure if they will

How can I create function pointers from a string input in MATLAB?

跟風遠走 提交于 2019-11-30 13:10:25
If I use the inline function in MATLAB I can create a single function name that could respond differently depending on previous choices: if (someCondition) p = inline('a - b','a','b'); else p = inline('a + b','a','b'); end c = p(1,2); d = p(3,4); But the inline functions I'm creating are becoming quite epic, so I'd like to change them to other types of functions (i.e. m-files, subfunctions, or nested functions). Let's say I have m-files like Mercator.m , KavrayskiyVII.m , etc. (all taking a value for phi and lambda ), and I'd like to assign the chosen function to p in the same way as I have

Matlab mex-file with mexCallMATLAB is almost 300 times slower than the corresponding m-file

那年仲夏 提交于 2019-11-30 09:32:10
I started implementing a few m-files in C++ in order to reduce run times. The m-files produce n-dimensional points and evaluate function values at these points. The functions are user-defined and they are passed to m-files and mex-files as function handles. The mex-files use mexCallMATLAB with feval for finding function values. I constructed the below example where a function handle fn constructed in the Matlab command line is passed to matlabcallingmatlab.m and mexcallingmatlab.cpp routines. With a freshly opened Matlab, mexcallingmatlab evaluates this function 200000 in 241.5 seconds while

How can I create function pointers from a string input in MATLAB?

自古美人都是妖i 提交于 2019-11-29 18:36:16
问题 If I use the inline function in MATLAB I can create a single function name that could respond differently depending on previous choices: if (someCondition) p = inline('a - b','a','b'); else p = inline('a + b','a','b'); end c = p(1,2); d = p(3,4); But the inline functions I'm creating are becoming quite epic, so I'd like to change them to other types of functions (i.e. m-files, subfunctions, or nested functions). Let's say I have m-files like Mercator.m , KavrayskiyVII.m , etc. (all taking a