Using MatLab function in C# and passing and receiving an array
3 views (last 30 days)
Show older comments
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?*
}
}
}
0 Comments
Answers (1)
Varun Bhaskar
on 10 Aug 2015
Hello,
Refer to the following documentation links in order to learn how to retrieve data from MATLAB into your C# application:
0 Comments
See Also
Categories
Find more on .NET Client Programming in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!