programming with matlab and .NET C#

3 Ansichten (letzte 30 Tage)
Hui
Hui am 30 Apr. 2014
Kommentiert: Walter Roberson am 18 Nov. 2016
Hello ,all!
I want to pack the nlinfit method as a Class(.NET assembly) so I can use in my C# application. But there is a problem:
There are four parameters in nlinfit method:( X,Y,MODELFUN,BETA0 ) . Among them X Y and BETAO all are matrix(Class Array can be transform to Class MWArray in C#),but parameter MODELFUN is a funtion in matlab. What does function in matlab means in .NET?

Akzeptierte Antwort

Daniel Pereira
Daniel Pereira am 30 Apr. 2014
Bearbeitet: Daniel Pereira am 30 Apr. 2014
I would suggest what I think is the easiest way:
If MODELFUN is a matlab function handle, use inside your "matlab method" the command str2func , in order to transform a string into a function handle
function out = mynlinfit(X,Y,MODELFUN,BETA0)
MODELFUN2 = str2func(MODELFUN); % MODELFUN is a string. e.g: '@(x) cos(x)'
% MODELFUN2 is a function handle.
out = nlinfit(X,Y,MODELFUN2,BETA0);
Now, MODELFUN2 is a function handle (which can be used in the original nlintfit), while your method's input MODELFUN is a string, which you don't need to cast in C#, as .NET strings are directly interpreted by matlab.
Hope it helps.
  3 Kommentare
Limin Wang
Limin Wang am 18 Nov. 2016
In my case, the MODELFUN is not a matlab function but a function in C#. How could I transfer this function from C# to Matlab? Now I want to pack the gaoptimset method:( FINESSfCN,nvars,...)in the matlab toolbox as a Class(.NET assembly) so I can use in my C# program, but FINESSfCN is a function in my C# program. What should I do to transfer the function in the C# to the gaoptimset method?

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by