Test Your .NET Development Environment - MATLAB & Simulink (original) (raw)
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 byfullfile(_`matlabroot`_,"extern","examples","engines","dotnet")
, where _`matlabroot`_
is the path returned by the MATLABmatlabroot
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 MATLABcopyfile
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_`matlabroot`_/extern/examples/engines/dotnet
folder. - Call
dotnet run
from the_`matlabroot`_/extern/examples/engines/dotnet/console
folder. - On Windows platforms, call
dotnet run
from the_`matlabroot`_/extern/examples/engines/dotnet/gui
folder.