Calling MATLAB function from C# Windows Application
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
I'm trying to learn how to use MATLAB functions from C# with a simple addition function
like this.
function [ sum ] = VisualTest( x,y )
%UNTITLED Summary of this function goes here
% Detailed explanation goes here
sum = x + y;
end
I compiled the function into a .NET Assembly using the Library Compiler using this tutotial
I implemented this function into a simple windows form application with Visual Studio 2019, however when I run the Form my result is just "System.Object[]", not an actual value. Is the actual value hidden in this output, or is my function not working properly?
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using VisualTestNative;
using System.Runtime.InteropServices;
namespace MatLabTest
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Button1_Click(object sender, EventArgs e)
{
object Vis;
object x = Convert.ToDouble(textBox1.Text);
object y = Convert.ToDouble(textBox2.Text);
object[] res = null;
Vis = new Class1();
Class1 VisRef;
VisRef = (Class1)Vis;
res = VisRef.VisualTest(1, x, y);
Console.WriteLine(res.ToString());
textBox3.Text = Convert.ToString(res);
}
}
}
0 Kommentare
Antworten (1)
Tzu-Hsun Kao
am 7 Aug. 2020
Maybe you should try to add a reference to your project to the MATLAB COM object.
For example, in Microsoft Visual Studio, open your project. From the Project menu, select Add Reference. Select the COM tab in the Add Reference dialog box. Select the MATLAB application.
0 Kommentare
Siehe auch
Kategorien
Mehr zu .NET Methods in MATLAB finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!