The function [addRlt]=meiyou (a, b)
% matrix addition, subtraction
[m1, n1]=size (a);
[m2, n2]=size (b);
AddRlt=a \ b;
Here is as experimental program (1) independent run successfully,
Using System;
Using System. Collections. Generic;
Using System.Com ponentModel;
Using System. The Data;
Using System. Drawing;
Using System. Linq;
Using System. The Text;
Using MathWorks.MATLAB.NET.Arrays;
Using MathWorks.MATLAB.NET.Utility;
Using meiyou;//matlab functions in the a/b
Using System. Windows. Forms;
The namespace meiyoudiande
{
Public partial class Form1: Form
{
Public _click ()
{
InitializeComponent ();
//meiyou. Class1 mm=new meiyou. Class1 ();
}
Private void Form1_Load (object sender, EventArgs e)
{
Meiyou. Class1 mm=new meiyou. Class1 ();
Double [and] c=new double (2000, 1);//define the type of receiving output parameters in c #
Double [] b=new double [2000];
For (int I=0; i <2000; I++)
{
[I]=I + 1 b;
}
//the two input parameters are converted to intermediate type, middle type is also the matrix so to indicate the dimension
//here will be two input parameters can be converted into two three lines of two columns of the matrix
MWNumericArray matlab_b=new MWNumericArray (2000, 1, b);
MWNumericArray matlab_a=new MWNumericArray (new double [2000, 2000]).
For (int I=1; i <=2000; I++)
{
Matlab_a [, I]=1;
}
//input parameters successfully into two MWArray element type
MWArray agrsIn=new MWArray [] [] {matlab_a, matlab_b};
//declare output parameters are two MWArray element type, be sure to write the number
MWArray [] agrsOut=new MWArray [1].
//call matlab function, 2 said the number of output parameters, output parameters before need to add the ref keyword
//this case for two to three lines to add and subtract two columns of the matrix phase
Mm. Meiyou (1, ref agrsOut, agrsIn);
//the two output parameters into the middle type
MWNumericArray net_c=agrsOut [0] as MWNumericArray;//matlab functions the first output parameter
//converted to receive the parameters on the c #
C=(double [and]) net_c. ToArray ();//into a two dimensional array
//it is important to note that the final receiving parameter transformation, different types of receiving parameters with different transition function
//two dimensional array using ToArray () function transformation
//a one-dimensional array with ToVector (MWArrayComponent. Real) function transformation
//a single double value with ToScalarDouble () function transformation
//a single int value with ToScalarInteger () function transformation
For (int I=0; i <2000; I++)//output results show
{
ListBox1. Items. The Add (c [I, 0]. ToString ());
}
}
}
}
Question 2 above programs can run independently but think from another form call this routine will go wrong
Call the form (2) the code is as follows:
Using System;
Using System. Collections. Generic;
Using System.Com ponentModel;
Using System. The Data;
Using System. Drawing;
Using System. Linq;
Using System. The Text;
Using System. Windows. Forms;
Using System. Diagnostics;
Embedded namespace exe
{
Public partial class Form1: Form
{
Public _click ()
{
InitializeComponent ();
}
Private static System. Diagnostics. The Process p;
Private void button1_Click (object sender, EventArgs e)
{
//System. Diagnostics. The Process p=Process. The Start (@ "F: \ Bin \ \ qq qq. Exe");
System. Diagnostics. The Process p=Process. The Start (@ "C: \ Users \ experimental 18 Zhang \ Desktop \ \ meiyoudiande \ bin \ Debug \ meiyoudiande exe");
P.W aitForExit ();//the key for the external program exits to execute down
P. tartInfo. WindowStyle=System. Diagnostics. ProcessWindowStyle. Normal;
}
}
}
Name of the file on the comparison of exotic flowers don't mind==
Application (2) calls (1) the results of the following
System. TypeInitializationException: "meiyou. Class1" of type initializers cause abnormal, - & gt; System. TypeInitializationException: "MathWorks.MATLAB.NET.Utility.MWMCR" of type initializers cause abnormal, - & gt; System. Exception: Trouble the initializing libraries required by the.net Assembly.
Problems is still the initial value exclude platform X86 x64 problem set the environment variable pretty helpless look forward to you greatly improve!
CodePudding user response:
The building Lord, ask, problem solved? I also met the same problem,