c#์ ์ฌ์ฉํ์ฌ ํ๋ก๊ทธ๋จ์ ์์ฑํ๋ค๊ฐ ๋ณด๋ฉด ์ํ๊ณผ ๊ด๋ จ๋ ๋ผ์ด๋ธ๋ฌ๋ฆฌ๊ฐ ๋ถ์กฑํ๋ค๋ ์๊ฐ์ด ๋ค๋๊ฐ ์์๋ค. ๊ทธ๋ด ๋๋ง๋ค matlab์ c#์ผ๋ก ์๋ํํ ์ ์๋ ๋ฐฉ๋ฒ์ด ์์์ผ๋ฉด ์ข๊ฒ ๋ค๋ ์๊ฐ์ ํ๊ณค ํ๋๋ฐ, matlab์ ์ด๋ฏธ ๊ทธ ๊ธฐ๋ฅ์ ์ง์ํ๊ณ ์์๋ค.
https://kr.mathworks.com/help/matlab/matlab_external/call-matlab-function-from-c-client.html
C# ํด๋ผ์ด์ธํธ์์ MATLAB ํจ์ ํธ์ถํ๊ธฐ - MATLAB & Simulink - MathWorks ํ๊ตญ
๋ค์ MATLAB ๋ช ๋ น์ ํด๋นํ๋ ๋งํฌ๋ฅผ ํด๋ฆญํ์ต๋๋ค. ๋ช ๋ น์ ์คํํ๋ ค๋ฉด MATLAB ๋ช ๋ น ์ฐฝ์ ์ ๋ ฅํ์ญ์์ค. ์น ๋ธ๋ผ์ฐ์ ๋ MATLAB ๋ช ๋ น์ ์ง์ํ์ง ์์ต๋๋ค.
kr.mathworks.com
์ ๋ฐฉ๋ฒ์ ์ฐธ๊ณ ํ๋ฉด ๋๋๋ฐ, ์ ๋ฐฉ๋ฒ์ ๊ทธ๋๋ก ์ฌ์ฉํ๋ฉด ์๋๊ณ ์๋์ ๊ฐ์ด ๋ณํํ์ฌ ์ ์ฉํ๋ฉด ๋๋ค.
1. Visual Studio ์์ COM ๋ผ์ด๋ธ๋ฌ๋ฆฌ Matlab Application (Version X.X) Type Library ์ถ๊ฐ
2. ์๋ ์ฝ๋๋ฅผ ์ถ๊ฐํด์ ์ฌ์ฉ
public static class _Matlab
{
private static Type mlType = null;
private static MLApp.MLApp matlab = null;
public static Test()
{
if (matlab = null) // matlab ์ธ์คํด์ค๊ฐ ํ๋๋ง ์คํ๋๋๋ก null check!!
{
mlType = Type.GetTypeFromProgId("Matlab.Autoserver");
matlab = Activator.CreateInstance(mlType) as MLApp.MLApp;
matlab.Visible = 0;
System.Threading.Thread.Sleep(2000);
}
var Result = matlab.execute("1 + 1");
// ans =
//
// 2
matlab.Quit();
}
}
์ ๊ธฐ๋ฅ์ ์ฐธ๊ณ ํ๋ค๋ฉด, ๋ท๋ท ํ๋ ์์ํฌ์ ๋จ์ ์ธ ์ํ ๋ผ์ด๋ธ๋ฌ๋ฆฌ์ ๋ถ์ฌ๋ฅผ ์ปค๋ฒํ ์ ์๋ค. ๋ค๋ง, Matlab์ด ๋ฌด์กฐ๊ฑด ์ค์น๋์ด ์์ด์ผ ํ๊ณ , Matlab์ ์ํ ์๋ฌ ๋ฐ์์ ๋๋ฒ๊น ์ด ์ด๋ ค์ธ ์ ์๋ค๋ ๋จ์ ์ด ์กด์ฌํ๋ค.
<์ฐธ๊ณ >
1. Matlab Runtime ๋ฒ์ ํ์ธ
MATLAB Runtime - MATLAB Compiler
MATLAB Runtime์ ์ปดํ์ผ๋ MATLAB ์์ฉ ํ๋ก๊ทธ๋จ ๋๋ ๊ตฌ์ฑ ์์๋ฅผ ์คํํ ์ ์๋ ๋ ๋ฆฝ ํ ๊ณต์ ๋ผ์ด๋ธ๋ฌ๋ฆฌ ์ธํธ์ ๋๋ค. MATLAB, MATLAB Compiler ๋ฐ MATLAB Runtime์ ํจ๊ป ์ฌ์ฉํ๋ฉด ์์น์ฐ์ฐ์์ฉ ํ๋ก๊ทธ๋จ ๋
kr.mathworks.com
Create MATLAB Server - MATLAB & Simulink - MathWorks ํ๊ตญ
๋ค์ MATLAB ๋ช ๋ น์ ํด๋นํ๋ ๋งํฌ๋ฅผ ํด๋ฆญํ์ต๋๋ค. ๋ช ๋ น์ ์คํํ๋ ค๋ฉด MATLAB ๋ช ๋ น ์ฐฝ์ ์ ๋ ฅํ์ญ์์ค. ์น ๋ธ๋ผ์ฐ์ ๋ MATLAB ๋ช ๋ น์ ์ง์ํ์ง ์์ต๋๋ค.
kr.mathworks.com
'๐ฅ๏ธ Coding > MATLAB & Simulink' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
matlab.System ์ค๋ธ์ ํธ ์ค๋ช (Simulink, Matlab System ๋ธ๋ก) (0) | 2021.08.06 |
---|---|
MATLAB , C# .NET DLL ๊ฐ ์ฌ์ฉ๋ฐฉ๋ฒ (0) | 2021.07.26 |