Calling a C sharp function from Matlab

조회 수: 3 (최근 30일)
Maria Isabel
Maria Isabel 2012년 11월 23일
답변: Priya Jeganathan 2021년 9월 15일
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.

답변 (2개)

Ken Atwell
Ken Atwell 2012년 11월 27일
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:
  댓글 수: 1
Shahidul Asif
Shahidul Asif 2021년 3월 8일
How do I expose the codes as you mentioned?

댓글을 달려면 로그인하십시오.


Priya Jeganathan
Priya Jeganathan 2021년 9월 15일
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.

카테고리

Help CenterFile Exchange에서 Financial Toolbox에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by