How to build matalb dll for c# winform dotnet framwork app

29 次查看(过去 30 天)
Hi. I'm using matlab2020a 2 version
I want to build my matlab function dll for c# winform gui app.
My gui c#app will call matlab func dll(by adding dll to c#reference)
and by using data loaded by c#, I want to draw graph, get result values to c# app.
So, myquestion are below.
1. Can I build my matlab functions dll-files for c# winform app? 2. How can I manage event things between matlab dll-file and c# * of course i know matlab app... but now I'm making united tool using c# At first I tried to make app without matlab, but data is too large(1M point x- axis) and it has 50layers. Some data is empty. I'll use Matlab's normalize(meshgrid things)func and interpolation func and plot func in my matlab code.
Data is too large, to show all data on graph, Icannot deal with this using c# math lib only.

回答(1 个)

arushi
arushi 2024-9-6
Hi YEONWOO,
I understand that you have a MATLAB code which needs to be converted to DLL file that is to be used in C# winform.
To generate DLLs from MATLAB files you can use the MATLAB Coder App.
  1. From the Apps toolbar select MATLAB Coder.
  2. Select the File which you want to convert.
  3. Define the input Type for your MATLAB Function.
  4. Check For Runtime issue and click next.
  5. Click on the drop-down arrow besides "Generate"
  6. Select Built type: Dynamic Link Library
  7. Click through all the next steps and generate the DLL.
Refer to the documentation below to get more information on using MATLAB coder app.
When using MATLAB DLL files in a C# application, you can manage events by following these steps:
  • In your MATLAB code, you can define events using the “event” keyword. For example, you can define an event named "DataReady" as follows:
classdef MyClass < handle
events
DataReady
end
end
  • Within your MATLAB code, you can use the “notify” function to raise events.
  • Use MATLAB Compiler to generate the DLL file from your MATLAB code and import the generated DLL file as reference in your C# project.
  • In your C# code, you can define event handlers to handle the events raised by the MATLAB DLL
By defining events in MATLAB and handling them in your C# application, you can establish communication and synchronization between the MATLAB DLL and your C# code. This allows you to react to events raised by the MATLAB code and perform appropriate actions in your C# application.
Refer to the documentation below to get more information on using events in MATLAB.

类别

Help CenterFile Exchange 中查找有关 MATLAB Compiler 的更多信息

产品


版本

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by