๋ฐ์ํ
MATLAB์์ C#์ ํธ์ถํ๊ฑฐ๋ C#์์ MATLAB ๊ธฐ๋ฅ์ ํธ์ถํ๋ ๋ฐฉ๋ฒ์ ์๋์ ๊ฐ๋ค. (MATLAB ๋ฌธ์)
using System;
namespace netdoc
{
public class SampleRefTest
{
//test ref keyword
public void refTest(ref double db1)
{
db1 = db1 * 2;
}
}
}
MATLAB์์ ์ C# ํด๋์ค๋ฅผ ํธ์ถํ์ฌ ์ฌ์ฉํ๋ ๋ฐฉ๋ฒ์ ์๋์ ๊ฐ๋ค.
asmpath = 'c:\work\Visual Studio 2012\Projects\SampleRefTest\SampleRefTest\bin\Debug\';
asmname = 'SampleRefTest.dll';
asm = NET.addAssembly(fullfile(asmpath,asmname));
cls = netdoc.SampleRefTest;
db4 = refTest(cls,6);
// db4 = 12
๋ฐ๋๋ก C#์์ MATLAB์ผ๋ก ์์ฑ๋ ์คํฌ๋ฆฝํธ๋ฅผ ์ฌ์ฉํ๋ ๋ฐฉ๋ฒ์ ์๋์ ๊ฐ๋ค.
using System;
using System.Collections.Generic;
using System.Text;
namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
// Create the MATLAB instance
MLApp.MLApp matlab = new MLApp.MLApp();
// Change to the directory where the function is located
matlab.Execute(@"cd c:\temp\example");
// Define the output
object result = null;
// Call the MATLAB function myfunc
matlab.Feval("myfunc", 2, out result, 3.14, 42.0, "world");
// Display result
object[] res = result as object[];
Console.WriteLine(res[0]);
Console.WriteLine(res[1]);
// Get user input to terminate program
Console.ReadLine();
}
}
}
๋ฐ์ํ
'๐ฅ๏ธ Coding > MATLAB & Simulink' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
c# matlab ์๋ํ (0) | 2021.08.22 |
---|---|
matlab.System ์ค๋ธ์ ํธ ์ค๋ช (Simulink, Matlab System ๋ธ๋ก) (0) | 2021.08.06 |