As with the previous article, the engine is also the way, but the configuration method is very different.
Configuration environment: vs2013 (64-bit) +matlab2013a (64-bit) +win8.1 (64-bit)
Install the path with MATLAB: C:\Program files\matlab\r2013a as an example
1. Add Reference:
One is the reference to add MWArray.dll, the path is: C:\Program files\matlab\r2013a\toolbox\dotnetbuilder\bin\win64\v2.0,
Another is to add a reference to the MATLAB type library. Right-click Add Reference on Reference, as shown in the following figure
2. Add Namespaces:
Using MathWorks;
Using Mathworks.matlab;
Using MathWorks.MATLAB.NET.Arrays;
Using MathWorks.MATLAB.NET.Utility;
Using Mlapp;
3. Sample code:
A total of four ways were attempted, two of which were successful, two failed, and the specific code was as follows (added to the button event):
Engine Mode 1, failure
Mlapp.mlappclass matlab = new Mlapp.mlappclass ();
string command;
Command = "T=2:0.2:4*pi;y=sin (t);p lot (t,y)";
Matlab. Visible = 1;
Matlab. Execute (command);
Command = @ "Print" (GCF, '-djpeg ', ' c:\Test1 ');
Matlab. Execute (command);
pictureBox1.Image = Image.FromFile (@ "c:\Test1.jpg");
Engine mode 2, failure
Mlapp.dimlapp matlab = null;
Type Matlabapptype = System.Type.GetTypeFromProgID ("matlab.application");
matlab = System.Activator.CreateInstance (matlabapptype) as Mlapp.dimlapp;
string command;
Command = "T=2:0.2:4*pi;y=sin (t);p lot (t,y)";
Matlab. Visible = 1;
Matlab. Execute (command);
Command = @ "Print" (GCF, '-djpeg ', ' c:\Test1 ');
Matlab. Execute (command);
pictureBox1.Image = Image.FromFile (@ "c:\Test1.jpg");
Engine Mode 3, success
Mlapp.mlapp matlab = null;
Type Matlabapptype = System.Type.GetTypeFromProgID ("matlab.application");
matlab = System.Activator.CreateInstance (matlabapptype) as Mlapp.mlapp;
string command;
Command = "T=2:0.2:4*pi;y=sin (t); h = Plot (t,y)";
String path = Directory.GetCurrentDirectory ();//Get current path
Matlab. Visible = 0;
Matlab. Execute (command);
Command = @ "Print" (GCF, '-djpeg ', ' "+ Path +" \\Test1 ');
Matlab. Execute (command);
pictureBox1.Image = image.fromfile (path + "\\Test1.jpg");
Engine Mode 4, success
&n