C#. NET and MATLAB integration

Source: Internet
Author: User

In mathematical analysis tools, MATLAB is undoubtedly the leader, in addition to as a software tool, MATLAB custom programming language and mixed programming support, so that it can be compared with Python, R and other mathematical analysis language. Especially in some traditional fields of research, due to its specialization in the field of research, the researchers are generally the professional trained, while the computer is a sideline, so the application of MATLAB is far more extensive than Python and R.

MATLAB has a number of algorithm packages,. NET platform of F # is used for data analysis of the language, but in comparison, MATLAB algorithm more, computational efficiency is more efficient, and MATLAB drawing ability is very strong, on the other hand, Matlab in the traditional UI interface, program function control, system software integration, etc., so the C # WinForm and Matlab together, to achieve efficient, convenient, integrated mathematical analysis is a good solution, and MATLAB mixed programming can support the implementation of the scheme.

Matlab mixed programming, will be MATLAB platform (software, computing engine, DCOM service, command line interface, etc.) and C #. NET and other platforms, respectively, responsible for a certain part of the function, transmission of data and commands, together to achieve data analysis. Matlab and C #. NET implements mixed programming in two ways, one is to compile the Matlab script into a. NET assembly (DLL), and then C #. NET refers to the assembly for data analysis, and the other is C # calling Matlab to execute a MATLAB script (M file), which is commonly known as using the MATLAB engine.

There are advantages and disadvantages to both methods of integration, such as compiling to. NET assembly, limited by. NET assembly version, and needs to be compiled and used, not conducive to version updates, directly invoking the MATLAB engine, you need to install MATLAB software. Choose the integration mode, which can be determined according to the specific requirements and scenarios. There is a lot of information about programme one on the Internet, this post on the implementation of the plan two to explain.

The MATLAB platform provides the DCOM service, the command line interface two kinds of interfaces, the network generally can see the way of the DCOM service, this way can directly pass the command string to MATLAB instance (according to MATLAB type reflection to create MATLAB instance), Executes the code using its Excute method, and can get the return value. The second method invocation, MATLAB provides the DCOM service to the caller, so the execution process and the result of the MATLAB program do not give feedback and eventually feed the output back to the caller.

System.Type otype = System.Type.GetTypeFromProgID ("matlab.application"   Object ostr =object results = Otype.invokemember ("Execute"  NullNewObject[] {data});

A disadvantage of the above approach is that when the MATLAB execution time-consuming or error, difficult to troubleshoot, because the caller can only get to the execution results, unable to get to the MATLAB script debug, info and other information, so suitable for the algorithm mature, fixed scene. In the case of the algorithm is flexible or immature, tracking script execution is undoubtedly important, at this time can be used in mode two, called the MATLAB command line execution.

Invoke the MATLAB command line execution, MATLAB will launch the application, and then execute the script, the output information during the execution can be output to the command window, similar to the analysis of the use of MATLAB analysis, just as the analysis process to achieve integration, automation.

C#. NET and MATLAB integration

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.