Calling a C sharp function from Matlab

5 visualizzazioni (ultimi 30 giorni)
Maria Isabel
Maria Isabel il 23 Nov 2012
Risposto: Priya Jeganathan il 15 Set 2021
I´m developing a project with Matlab but I need to link it with csharp functions (speed requirements). Can you please explain me how to do it? Do you have any example? I think is not necessary to use Mex function, can you please confirm?
Thank you in advanced for your support.

Risposte (2)

Ken Atwell
Ken Atwell il 27 Nov 2012
If you stick your C# code into a .NET library, you can call it from MATLAB. You should not need to write MEX glue code. Take a look here:

Priya Jeganathan
Priya Jeganathan il 15 Set 2021
Start
{
float daily, total_daily=0, total_averge = 0;% defining the variable
float highest = 0;
int average = 0;
int final_count = 0;
string rootFile = @"D:\External Work\2018-January-Averages-AGLHAL.txt"; % Opening the text file
string[] dir = File.ReadAllLines(rootFile);%Reading the text file values
for (int i = 0; i < dir.Length; i++)
{
daily = float.Parse(dir[i]); %place the daily averages into a 1D array.
highest = daily > highest ? daily : highest;
if (daily > 0.00)
{
average++;
}
total_daily = total_daily + daily;
}
total_averge = total_daily / average;
for (int i = 0; i < dir.Length; i++)
{
if (float.Parse(dir[i]) > total_averge)
{
final_count++;
}
}
disp(" Summary Information for AGLHAL");
disp(" File Name : 2018-January-Averages-AGLHAL.txt");
if (highest == 0.00 && average == 0) //if there are no daily averages above 0.
{
disp("Max :" + highest.ToString("0.#"));
disp("Total Avaerage :" + average);
}
else
{
disp("Maximum Daily Average=" + highest.ToString("0.#")); //Maximum Daily Average
disp("Number of Daily Averages > 0 =" + average); //Number of Daily Averages > 0
disp("Average of Daily Averages that are > 0=" + total_averge.ToString("0.##")); //Average of Daily Averages that are > 0
disp("Number of Daily Averages > Average=" + final_count); //Average of Daily Averages that are > 0
}
input();
}
Until fileVariable.endOfFile // closing the text file
End.

Categorie

Scopri di più su MATLAB Compiler SDK in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by