简体   繁体   English

是否可以在MatLab中使用.NET应用程序?

[英]Is it possible to use .NET application in MatLab?

I feel at home in C# and I'll design a console application that will fetch some data from a web service. 我觉得在C#中有家,我将设计一个控制台应用程序,它将从Web服务中获取一些数据。 I'd like to allow a group of scientists to use the data in MatLab. 我想让一组科学家使用MatLab中的数据。 One way to achieve that is to store it in a file on the HDD and then load the contents of it into MatLab. 实现这一目标的一种方法是将其存储在HDD上的文件中,然后将其内容加载到MatLab中。

That got me thinking, though. 但这让我想到了。 Is it possible to create a function in MatLab that calls an EXE created in C# so my scientific friends can go: 是否可以在MatLab中创建一个函数来调用在C#中创建的EXE,以便我的科学朋友可以去:

a = GetMeSomeData()

and populate the variable a with the response of the service? 并使用服务的响应填充变量a (I would, of course, format the data using my C# code so it'll fit the matrix model of MatLab.) (当然,我会使用我的C#代码格式化数据,因此它适合MatLab的矩阵模型。)

I've done some googling before I start working on this but most of the stuff I've found is about an old version of MatLab (2007) and it's said something about creating a COM object. 在我开始研究之前,我已经完成了一些谷歌搜索,但我发现的大部分内容都是关于MatLab(2007)的旧版本,并且说了一些关于创建COM对象的内容。

You might want to take a look at this: Using .NET libraries in MATLAB . 您可能想看看这个: 在MATLAB中使用.NET库

There's plenty of documentation there. 那里有很多文档。

Start with NET.addAssembly ('path-to-dll) , and then it seems you can just use the classes normally as you would in .NET. NET.addAssembly ('path-to-dll) ,然后看起来你可以像在.NET中那样正常使用这些类。

You might also want to take a look at Using Arrays with .NET Applications . 您可能还想看看使用.NET应用程序的数组

You can easily call functions in a .NET assembly. 您可以轻松调用.NET程序集中的函数。 First you have to tell Matlab what assembly you are going to use: 首先,您必须告诉Matlab您要使用的装配:

NET.addAssembly("path//to//assembly.dll");

After that, you just call functions in your m-files: 之后,您只需调用m文件中的函数:

foo = Namespace.Class.FunctionFoo(input1, input2);
bar = Namespace.Class.FunctionBar(input1, input2);

You can even have multiple outputs. 你甚至可以有多个输出。 AC# function like this: AC#功能如下:

public void MultipleOut(int in1, int in2, out int out1, out int out2)
{ ... }

can be called like this in Matlab: 可以在Matlab中这样调用:

[out1, out2] = Namespace.Class.MultipleOut(in1, in2);

To answer the question directly, you can use the system command or ! 要直接回答问题,可以使用system命令或! in MATLAB to execute an external process. 在MATLAB中执行外部进程。 Once it returns you can read and parse the output from your MATLAB function. 一旦它返回,您可以读取并解析MATLAB函数的输出。 Wrap that all up in a MATLAB .m file and you have what you describe in the question. 将所有内容全部包含在MATLAB .m文件中,并且您拥有在问题中描述的内容。

Of course, you could just access the web service directly from MATLAB with createClassFromWsdl . 当然,您可以使用createClassFromWsdl直接从MATLAB访问Web服务。 And as others point out, NET.addAssembly allows you to import and use your .net assembly directly from MATLAB, which may be cleaner than parsing text file output. 正如其他人所指出的, NET.addAssembly允许您直接从MATLAB导入和使用.net程序集,这可能比解析文本文件输出更清晰。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 是否可以在.Net Core 2控制台应用程序中使用WCF? - Is it possible to use WCF in a .Net Core 2 console application? opos应用程序是否可以将pos用于.NET驱动程序 - Is it possible for an opos application to use pos for .NET driver 是否可以使用Matlab创建地图应用程序? - Is it possible to create a maps application with Matlab? 可以使用.NET桌面应用程序作为Google Cloud Messaging通知的接收者吗? - Is it possible to use a .NET desktop application as the receiver for Google Cloud Messaging notifications? ASP.NET可以在库中使用Session和HttpContext.Application - ASP.NET is it possible to use Session & HttpContext.Application in a library 是否可以使用 dotnet new 创建一个 ASP.NET Web Application Empty .Net Framework 4.7.2 项目? - Is it possible to use dotnet new to create an ASP.NET Web Application Empty .Net Framework 4.7.2 project? 是否有可能在.NET应用程序中运行python? - Is it possible run python in .NET application? 是否可以反编译整个.NET应用程序? - Is it possible to decompile the whole .NET application? 是否可以将MVC控制器用于带有Web窗体的ASP.NET Web应用程序? - Is it possible to use MVC Controllers for ASP.NET Web Application with Web Forms? 是否可以在.Net GridView中使用EditForm? - Is it possible to use EditForm in a .Net GridView?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM