Using MatLab function in C# and passing and receiving an array

조회 수: 3 (최근 30일)
Mehdi
Mehdi 2015년 8월 7일
답변: Varun Bhaskar 2015년 8월 10일
I tried a lot to find a clear description about this issue but most of them do not cover my question.
How can I pass 2D array to function and receive it?
The following code is my MatLab function:
function V = Mfunction(f,U,A)
% f is a vector
% A is a double number
% u is a n x n matrix
% output V is a n x n matrix
n = length(U);
for i=2:n+1
for j=2:n+1
U2(i,j) = U(i+1,j)/A;
end
end
e = Mfunction(f,U2);
V = U + e;
This is my C# code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using MathWorks.MATLAB.NET.Arrays;
using MathWorks.MATLAB.NET.Utility;
using Mfunction;
namespace matlabApplication
{
class Program
{
static void Main(string[] args)
{
int n = 100;
double[,] U = new double[n, n];
double[] f = new double[n];
// some calculations such as follow
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= n; j++)
{
U[i,j] = U[i,j] + 10;
f[i,j] = U[i,j] * 10;
}
}
*// Now I need to pass f & U into the Matalb function
// How?*
MLApp.MLApp matlab = new MLApp.MLApp();
matlab.Execute(@" cd C:\Users\jc262819\Documents\MATLAB");
*// After calculation I need to save the output of Matlab function (V) in an array in c#
// How?*
}
}
}

답변 (1개)

Varun Bhaskar
Varun Bhaskar 2015년 8월 10일
Hello,
Refer to the following documentation links in order to learn how to retrieve data from MATLAB into your C# application:

카테고리

Help CenterFile Exchange에서 .NET Client Programming에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by