vb.net m file that calls MATLAB (generates COM control)

Source: Internet
Author: User

A. Version Description:VS2008,matlab2010b

Second, installation Mcrinstaller

in the path C:\Program Files\matlab\r2010b\toolbox\compiler\deploy\win32 under

Third, in the MATLAB Configure the environment in the command window

1. Input: mbuild–setup The following interface appears, I chose [2] own compiler, not MATLAB bring your own.

2. Open it

3. Then pop up the following dialog box

Name my own life, my name is recognition. Select Generic COM Component. Click "OK". The following interface appears on the right side of Matlab

Click "Add Class", Name your own class, my name is recognition. Click "Add Files" to add your own m file, my main program is called Multimeter1. The subroutine that is called is lianxu1 and Vcmubanpipei ... Add to the bottom is my template picture, the program used to do not need to change the picture can be placed here. No need to add images.

Then click on the first icon, build

Wait 2-3 minutes, and you're done, like

Here, a folder will be generated under the path you choose recognition Open it

There will be a distrib and src two folders. The dll we want is inside the distrib.

This is the DLL I want.

If you call Matlab's M file on a computer that already has MATLAB installed, this DLL will be OK. If you want to get out of the MATLAB environment, we need to pack.

Add an MCR and package the MCR in. Then click the Second pack icon. To the right of the build icon.

Packaging finished, my program before packaging the DLL only 2 m, packaged after the 175M ...

There is one more in the Distrib folder just now. BAT file.

There is also an EXE

To the end of the operation of Matlab ....

DLL Register

The DLL generated by MATLAB, the registered DLL can be referenced by the project.

Third, on VB . NET the Operation

1. Add Reference

Add MWArray.dll the reference to my matlab2010b not inside, under the Internet, or looking for a lower version of the MATLAB , such as MATLAB7.0 inside it, test it inside your computer and add a reference to it.

Add MWComUtil.dll the reference, MATLAB below there, find yourself, Add.

Add the one you just made DLL .. My name is recognition_1_0.dll .

altogether added a 3 a DLL , the lack of a can not AH!!!

2 Import Namespaces

3 called DLL the program

This is my first sentence: an instance of an object Dim * * As New file name . class name

第二、三、五、六 Sentence: Set the input parameters of the function, my parameters are two, one is the picture img One is a number . angle.

Four: Object output parameters

seventh sentence: Call MATLAB of the multimeter function , parameter Description: " 1 "

Represents the number of output parameters; "Result" is an output parameter, and IMG and angle are input parameters. So I can get the results. I am a digital image to identify the program, the following is the result.

Important NOTES:

1.. The above speed is very slow, the reason for the slow is the first sentence, when the object of the instance, if the function is called multiple times, we want the program to do only one instance object, so I put these words in the module inside:

The procedure should read:

So the first call is slow, and then the speed is fast.

2. The previous call DLL has not been successful, has been jumping out of the box probably said that the JVM virtual memory is not enough, increase the virtual memory of the computer is not used, headache for four days, the last reason may be the program inside the instantiation of too many objects, memory spikes.

So in the program loading the window, I added several sentences to reclaim the memory, and finally resolved.

Gc. Collect ()

3. If the Matlab m file also needs to use some images, text files, put these files into. NET works under the Bin-dedug below is good, this is the default path.

4. The call to Matlab generates COM faster than the EXE generation, the preferred COM method.

This is called EXE's. NET program, paste retention, Myexe.exe is the MATLAB generated EXE, 123 words is called EXE.

Dim FileName2 as String ' execute matlab EXE file

FileName2 = Application.startuppath & "\myexe.exe"

System.Diagnostics.Process.Start (FileName2)

vb.net m file that calls MATLAB (generates COM control)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.