Matlab code to C + + code conversion and use of the full introduction __c++

Source: Internet
Author: User

1. In MATLAB, enter the command:

Mbuild-setup Install the compiler. (Note: Select the existing Vc/vs compiler on your computer and enter the appropriate path)

2. In MATLAB, enter the command:

Deploytool into this mode

3. Press the New button, select the C + + Shared Library, name the project, and select the path. Then add files, the M file will be converted to choose good. Finally, build the project and compile the M file. After the compilation succeeds, the code is generated under the Distrib folder in the specified directory. This folder generates a DLL file, a header file, and a Lib file. (note here is the MATLAB is divided into 32-bit version and 64-bit version, with the corresponding version of MATLAB follow this process to come down to generate the corresponding version of the DLL file and lib file.) So, when you call in VS, you want to adjust to the appropriate version. For example, using the 64-bit MATLAB generated DLL and lib file to be in VS in the x64 platform to run, or will produce link error. Be aware of the platform's unification, vs some controls, such as the Comm control only support 32-bit, so for unified use, the front also use 32-bit MATLAB

4. Copy the file generated in step 3rd to the VS project.

Copy the Include folder under Matlab/extern to the project in VS and add it to the inclusion directory of the VC + + directory.

Copy the Libmat.lib,mclmcr.lib,mclmcrrt.lib under Matlab/extern/lib/win64/microsoft to the VS project and add these libraries to the linker/input/attach dependencies.

5. Call the DLL in code.

(1) Initialization of the Library Mclinitializeapplication (null,0)

Xxxinitialize () xxx is the name of the file generated in step 3rd

(2) operation of the Mwarray

such as Matlab China denoising function Wden (IN1,IN2,IN3,IN4,IN5,IN6);

Transformed into this:

extern lib_wden_cpp_api void Mw_call_conv wden (int nargout, mwarray& xd, mwarray& cxd, mwarray& lxd, const MwA rray& in1, const mwarray& in2, const mwarray& in3, const mwarray& in4, const mwarray& IN5, const Mwarr ay& in6);

Number of nargout ——— output variables

Signal of xd--output variable after impatient

cxd--output Variable xd's Qi Xiaobo

lxd--output Variable xd's Qi Xiaobo

in1--Input Variable raw signal

in2--input variable threshold selection Rule optional mode: ' Rigrsure ', ' heursure ', ' sqtwolog ', ' Minimaxi '

in3--input variable soft threshold or hard threshold optional mode: ' s ' or ' h '

in4--input variable threshold scale change optional mode: ' One ', ' sln ', ' mln '

in5--input variable wavelet transform layer number

in6--input variable wavelet types such as ' DB10 ', ' SYM8 '

Example: to Achieve Xd_filter = Wden (XD, ' Minimaxi ', ' s ', ' mln ', 5, ' DB10 '); The code is as follows:

const int datanum = 5500;        
Char str1[9] = "Minimaxi";
Char str2[2] = "s";
Char str3[4] = "mln";
int  STR4 = 5;
Char str5[5] = "DB10";
Mwarray Str1 (str1);
Mwarray Str2 (str2);
Mwarray STR3 (STR3);
Mwarray STR4 (STR4);
Mwarray STR5 (STR5);
Mwarray XD (Datanum, 1, mxdouble_class);
Mwarray Xd_filter (Datanum, 1, mxdouble_class);
Mwarray cxd (datanum,1, mxdouble_class);
Mwarray lxd (datanum,1, mxdouble_class);
Xd. SetData (in, datanum);
Wden (1, Xd_filter, Cxd, Lxd, XD, Str1, STR2, STR3, STR4, STR5);
Xd_filter. GetData (out, datanum);

(3) The class of the project can be further written into a DLL form for later convenience.

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.