I attached to the MATLAB configuration process is also uploaded to everyone.
"Reprint" finally learned C # call Matlab function, originally so simple (also can download attachment view)
Your own configuration:
(1) Microsoft Visual Studio 2005
(2) Matlab r2009a
(3) IIS 6.0
The first step:
First install MATLAB;
Install Visual Studio 2005 or later;
Install MCRInstall.exe, I found it here after the installation of MATLAB: D: "Program Files\matlab\r2009b\toolbox\compiler\deploy\win32
Click: My Computer-Properties-advanced-environment variables-System Variables-path-edit, in the variable value input box, do not delete the previous string, the first to add the MCR installation path, such as: D: "Program Files\matlab\matlab Compiler Runtime\v80\bin\win32; Then identify, save, and restart your computer. (I just don't know if I need these two steps. When you create a MATLAB Access object in C #, it appears: "The type initializer for XXX throws an exception. ", completely don't understand what the reason is, was delayed a lot of time until the installation of MATLAB 2008b, carefully read it generated by the Readme.txt just know)
Step Two: Enter Mbuild-setup in the command window of MATLAB as shown below
>> Mbuild-setup
Choose your compiler for building standalone MATLAB applications:would do like Mbuild to locate installed compile RS [y]/n? n% Select n
Select a compiler:
[1] lcc-win32 C 2.4.1
[2] Microsoft Visual C + + 6.0
[3] Microsoft Visual C + +. NET 2003
[4] Microsoft Visual C + + 2005
[5] Microsoft Visual C + + 2005 Express Edition
[6] Microsoft Visual C + + 2008
[0] None compiler:4% Select 4, other compilers can choose the appropriate option, I have not verified
The default location for Microsoft Visual C + + compilers is C:\Program Files\Microsoft Visual Studio 8, but that Direc Tory does not exist on the this machine.
Use C:\Program Files\Microsoft Visual Studio 8.0 anyway [y]/n? n% Select n
Please enter the location of your compiler: [C:\Program Files\Microsoft Visual Studio 9] D:\Program Files\Microsoft Visual Studio 8.0% Choose your own current installation path
Please verify your choices:Compiler:Microsoft Visual C + + 2005 Location:d:\program Files\Microsoft Visual Studio 8.0 are These correct [y]/n? Y% see above information, if Y is selected correctly
Warning:mbuild requires that the Microsoft Visual C + + 8.0 Directories "VC" and "Common7" be located within the same paren T directory. Mbuild Setup expected to find directories named "Common7" and "VCs" in the directory: "C:\Program Files\Microsoft Visual St Udio 8 ". Trying to update options file:c:\documents and Settings\administrator\application data\mathworks\matlab\r2009a\ Compopts.bat from Template:d:\progra~1\matlab\r2009a\bin\win32\mbuildopts\msvc80compp.bat done ... To this MATLAB compiler setting succeeds.
Step three: Write the M file:
function Y=mymagic (x)
Y=magic (x);
Fourth step: Build the project:
In MATLAB click "File-new-development Project" to choose your own project save directory and project name, such as E: "and MAGICPRO.PRJ type Select. NET Component, if you want to build a more generic COM component, Select Generic COM Component. Add just the M file to this new project. Click the Build the Project button (the icon for this button is the same as the build icon for the Microsoft Development tool) or right-click to select "Build" and wait 3 to 4 minutes. Build success.
Mcc-w ' dotnet:magicpro,magicpro,0.0,private '-d ' E:\magicpro\src '-t ' link:lib '-V ' class{magicpro:\work\mymagic.m} ' Compiler version:4.10 (r2009a) processing include files ... 2 Item (s) added. Processing directories installed with MCR ... The file E:\magicpro\src\mccExcludedFiles.log contains a list of functions excluded from the CTF archive. 2 Item (s) added. Generating MATLAB path for the compiled application ... Created path items. Begin Validation of Mex Files:sat Mar 09:22:22 The End validation of Mex Files:sat Mar 09:22:22-parsing file "D:\WORK\MYMAGIC.M" (Referenced from: "Compiler Command line". Parsing file "D:\Program files\matlab\r2009a\toolbox\compiler\deploy\deployprint.m" (Referenced from: "Compiler Command line ". Parsing file "D:\Program files\matlab\r2009a\toolbox\compiler\deploy\printdlg.m" (Referenced from: "Compiler Command Line ". Deleting 0 Temporary MEX authorization files. Generating file "E:\magicpro\src\Magicpro.cs". Generating file "E:\magicpro\Src\magicpronative.cs ". Generating file "E:\magicpro\src\readme.txt". Generating file "E:\magicpro\src\dotnet_mcc_component_data.cs". Executing command:c:\windows\microsoft.net\framework\v2.0.50727\csc.exe/nologo/optimize/doc: "E:\magicpro\src\ Magicpro.xml "/T:LIBRARY/R:" D:\Program files\matlab\r2009a\toolbox\dotnetbuilder\bin\win32\v2.0\mwarray.dll "/ Resource: "E:\MAGICPRO\SRC\MAGICPRO.CTF"/Out: "E:\magicpro\src\magicpro.dll" "E:\magicpro\src\Magicpro.cs" "e:\ Magicpro\src\dotnet_mcc_component_data.cs "Executing command:c:\windows\microsoft.net\framework\v2.0.50727\ Csc.exe/nologo/optimize/doc: "E:\magicpro\src\magicproNative.xml"/t:library/r: "D:\Program files\matlab\r2009a\ Toolbox\dotnetbuilder\bin\win32\v2.0\mwarray.dll "/resource:" E:\MAGICPRO\SRC\MAGICPRO.CTF "/Out:" E:\magicpro\src \magicpronative.dll "" E:\magicpro\src\MagicproNative.cs "" E:\magicpro\src\dotnet_mcc_component_data.cs "copying:e : \magicpro\src\magicpro.dll-E:\magicpro\distrib Copying:e:\magicpro\src\magicProNative.dll, E:\magicpro\distrib Copying:e:\magicpro\src\readme.txt, E:\magicpro\distrib compilation Completed successfully. The output is located in E:\magicpro\distrib. You can package the component by clicking on the ' package ' icon in the Deployment Tool toolbar, or by clicking the tools-& Gt Package menu, the Deployment Tool panel is selected. To include additional files on the package, click Project->settings).
Fifth step: Open 2005. New Web site new C # Web page Add Reference:
Select. NET, select one of the components of the Mathworks,.net Mwarrays API to add a reference: Select Browse, select the E: "Magicpro.dll file for the Magicpro\distrib directory that you just created with the deployment. Settings page, a text box (enter the cube's dimensions) a button (commit), a label (show Rubik's Cube). The code is as follows:
Using System.Configuration;
Using System.Collections;
Using System.Web;
Using System.Web.Security;
Using System.Web.UI;
Using System.Web.UI.WebControls;
Using System.Web.UI.WebControls.WebParts;
Using System.Web.UI.HtmlControls;
Using MathWorks.MATLAB.NET.Arrays;
Using Magicpro;
public partial class Default2:System.Web.UI.Page
{
protected void Page_Load (object sender, EventArgs e)
{
Label1.visible = false;
}
protected void Button1_Click (object sender, EventArgs e)
{
Label1.visible = true;
String html_value = "<table >";
int input = Convert.ToInt32 (TextBox1.Text);
Magicpro. Magicpro m = new Magicpro ();
Mwnumericarray x = new Mwnumericarray (input);
mwarray[] Argsout = new Mwarray[1];
mwarray[] Argsin = new mwarray[] {x};
M.mymagic (1, ref argsout, Argsin);
Mwnumericarray y = argsout[0] as Mwnumericarray;
Textbox1.visible = false;
Button1.visible = false;
for (int i = 1; I <= y.dimensions[0]; i++)
{
Html_value + = "<tr>";
for (int j = 1; J <= Y.dimensions[1]; j + +)
{
Html_value + = "<td>";
Html_value + = Y[i, j];
html_value+= "</td>";
}
Html_value + = "</tr>";
}
Html_value + = "</table>";
Label1.Text = Html_value;
}
}
Run input 4. Click the button to show the 4-order Rubik's Cube:
16 2 3 13
5 11 10 8
9 7 6 12
4 14 15 1 success
C # matlab Mixed programming