MyAdd.m in Matlab (you just need to replace it with your m file) file:
function [c] = MyAdd(a, b)
c = a + b;
1. Use mcc -W cpplib:libMyAdd -T link:lib MyAdd.m to generate what we need
libMyAdd.dll
libMyAdd.h
libMyAdd.lib
Copy these three files to the VS project directory
2. Select Project -> Project Properties. Select C/C++-> General- > Additional Include Directories: F:\Program files\MATLAB\R2012b\extern\include
3. Linker -> General -> Additional Library Directory: F:\Program files\MATLAB\R2012b\extern\lib\win64\microsoft
4. Linker -> Input -> Additional Dependencies: libMyAdd.lib; mclmcrrt.lib
5. C++ code:
#include <iostream>
#include "libMyAdd.h"
using namespace std;
void main()
{
libMyAddInitialize(); //libMyAdd.dll initial?initialization?function?number
mwArray a(1, 4, mxDOUBLE_CLASS); //Definition of a 1*4 array of numbers, your demand should be one? 1*n?
a(1, 1)=2; //Assign 3 value μ to the number group
a(1, 2)=2;
a(1, 3)=3;
a(1, 4)=4;
mwArray b(1, 4, mxDOUBLE_CLASS); //Define again to define a 1*4 array of numbers, yours should be? No? Need to be addicted
b(1, 1)=1; //Assign 3 value μ to the number group
b(1, 2)=2;
b(1, 3)=3;
b(1, 4)=4;
mwArray y(1, 4, mxDOUBLE_CLASS); //Definition? A? A? 1*4? Number group? Get? Get? Return? Return? Value μ
MyAdd(1, y, a, b); //In this a? function ˉ number, D, the first? a? parameter? The first set of numbers, the first set of two t sets of parameters? ? Yes ? Input ? Parameters?
cout<<y(1,1)<<"\t"<<y(1,2)<<"\t"<<y(1,3)<<"\t"<<y(1,4)<<"\n";
libMyAddTerminate(); //libMyAdd.dll's?Close?Close?Function ˉnumber
while(1);
}
The screenshot is: