Trying to launch a MATLAB plot program from a .NET C# windows application
이전 댓글 표시
Hi, I am trying to call a MATLAB .m file from a C# windows app. I was able to create a .NET assembly using the MATLAB compiler. I added a reference to the dll created by the compiler and had to change the visual studio application properties, platform target to x64 to get the C# app to build ok. I also added the MWArray dll as a reference, not sure if required. It looked like the compiler created 2 dlls, one with the Native keyword added. I included the other dll as well as the MWArray dll as references.
Anyhow I have something like using namespace; also have using Mathworks.NET; I have mlclass mymatlabclass=new new mlclass ();//mlclass is the class name of the matlab assembly. mymatlabclass.method(); the program should launch the MATLAB plot with the second line but just seems to hang running from the debugger in Visual Studio with no errors. I was able to instantiate the class ok.
댓글 수: 5
Kojiro Saito
2018년 9월 21일
Could you share some sample codes for our investigating in detail?
Paul
2018년 10월 3일
Paul
2018년 10월 3일
Paul
2018년 10월 3일
Paul
2018년 10월 3일
답변 (2개)
Kojiro Saito
2018년 10월 3일
Suppose you have compiled MATLAB function (call "NameofMethod") to .NET assembly (call Visual) and got Visual.dll. I think you need to enclose your codes with "try catch" because the class instantiation and method invocation would make their exceptions at run time.
using Visual;
using Mathworks.MATLAB.NET;
namespace YOURNAMESPACE
{
class Program
{
static void Main(string[] args)
{
Myclass callMat = null;
int numOfOutput = 0;
try
{
callMat = new MyClass();
callMat.NameofMethod(numOfOutput);
}
catch (Exception e)
{
Console.WriteLine(e);
throw;
}
}
}
}
댓글 수: 7
Paul
2018년 10월 4일
Paul
2018년 10월 4일
Paul
2018년 10월 4일
Kojiro Saito
2018년 10월 4일
That is a good news. Yes, we need to change platform target from any to x64 as the step 4 of this document describes. It's because MATLAB (& MATLAB Runtime ) supports only 64 bit.
Paul
2018년 10월 9일
Kojiro Saito
2018년 10월 10일
I'm not sure good way of debugging other than Visual Studio debugger, but there's a document of calling compiled MATLAB plot from C#. Please see this document (in Simple Plot section). It might be helpful.
Paul
2018년 10월 11일
카테고리
도움말 센터 및 File Exchange에서 Deploy to .NET Applications Using MWArray API에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!