Using C Math Library
To add support of MATLAB C Math Library follow these instructions:
1- Add following line at the end of stdafx.h
#include <matlab.h>
matlab.h is interface of MATLAB APIs. Add directory of MATLAB interface files (*.h) to Visual Studio (Tools -> Options -> Directories). For example: x:\matlab\extern\include where x is drive letter of matlab path.
2- Add desired libraries to your project (In this example, libmat.lib, libmx.lib, libmatlbmx.lib and libmatlb.lib)
3- Compile your project!
Sample Program
#include "stdafx.h"
int main(int argc, char* argv[])
{
double dblArray[]={1, 2, 3, 4, 5, 6, 7, 8, 9};
mxArray *A, *B; A=mxCreateDoubleMatrix(3, 3, mxREAL);
//copy array to matrix A
memcpy(mxGetPr(A), dblArray, 9 * sizeof(double));
A=mlfMTimes(A, A); //A=A.^2;
mlfPrintMatrix(A); //Creating Magic Matrix
B=mlfMagic(mlfScalar(3)); //Magic matrix of order 3
mlfPrintMatrix(B);
mxDestroyArray(A);
mxDestroyArray(B);
return 0; }