How to convert from MATLAB solver to C# code
55 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hello all.
I have some problem that converting MATLAB code to C# code.My experience with C# is very limited and I didn't find a solution of this matter.
Let me explain my scenario. I have a some function to solve the optimization problem. I used "lsqnonlin" function. When I used MATLAB coder in order to convert from MATLAB m-file to dll file, but I have some error messages.
First, I want to import the input data set from "mat" file, so I used "load" function in matlab code. But, code generation result shows "The function 'load' is not supported for standalone code generation. Either change the target to generate a MEX or S-function or use 'coder.load' to load the MAT file at compile time." messages. I want to solve this problem.
Second, when I convert MATLAB function such as "Lsqnonlin" or "load" embedded in MATALB to C# code, I want to know how to do easily. Is it possible to generate C# code through MATLAB coder directly?
Thank you for all about your help.
0 comentarios
Respuestas (2)
Navaneeth Raman
el 22 de Abr. de 2015
Hello,
MATLAB Coder does not have the capability to convert MATLAB Code to C# code. It can convert MATLAB Code to C/C++ code. That being said, not all MATLAB functions can be converted to C code. The following link gives a list of supported functions for code generation:
In this list 'lsqnonlin' is not one of the functions that is supported for code generation. As for your other error message with regard to loading a MAT file, the error is pretty clear. You can use coder.load as stated in the error message. To know more about it just type the following in the MATLAB command line:
>> doc coder.load
HTH, Navaneeth
1 comentario
Ah
el 25 de Nov. de 2016
Editada: Walter Roberson
el 26 de Nov. de 2016
Bill Chou
el 23 de Mzo. de 2020
Editada: Bill Chou
el 16 de Mayo de 2024
Yes, it's possible to use MATLAB Coder to integrate with C# applications. One would need to make some manually changes at the interface. Please see this article for more details:
In addition, generating the interface binding the generated C code to C# with something like SWIG is also an option. Here's an example:
0 comentarios
Ver también
Categorías
Más información sobre MATLAB Compiler SDK en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!