Test Your .NET Development Environment
MATLAB® engine API for .NET ships with example C# code that you can use to test your
environment and to become familiar with the use of the engine API. The source code is located
in the folder defined by
fullfile(
,
where matlabroot
,"extern","examples","engines","dotnet")
is the path returned by the
MATLAB
matlabroot
matlabroot
command.
The folder contains:
dotnet_engine_examples.sln
— Microsoft® Visual Studio® project files..cs
files — C# source files. These applications:Start a MATLAB instance and connect to it.
Close and dispose of the MATLAB session.
The
Program.cs
file is a console application that runs all of the example files included in the project.The
MainWindow.xaml.cs
file is a Windows® GUI application that calculates a factorial based on user input.README
— Text file that describes how to build and run the examples using Visual Studio.
Copy the files to a writable folder on your path using the MATLAB
copyfile
function:
copyfile(fullfile(matlabroot,"extern","examples","engines","dotnet","dotnet_engine_examples.sln"),".","f") copyfile(fullfile(matlabroot,"extern","examples","engines","dotnet","console\*.*"),".\console\","f")
If you are on a Windows platform:
copyfile(fullfile(matlabroot,"extern","examples","engines","dotnet","gui\*.*"),".\gui\","f")
Follow these instructions in the README
file to build and run the examples:
Verify that you have a supported version of .NET.
Set the run-time environment variable.
Call
dotnet build
from the
folder.matlabroot
/extern/examples/engines/dotnetCall
dotnet run
from the
folder.matlabroot
/extern/examples/engines/dotnet/consoleOn Windows platforms, call
dotnet run
from the
folder.matlabroot
/extern/examples/engines/dotnet/gui