Matlab C/C++ compiler Configration test code

Test if Microsoft Visual Studio is correctly configed to use Matlab C++ functions.
 
/*
  Name: Test for Matlab C++ Mathematics Functions
  Copyright: no
  Author:  <<MATLAB外部程序接口(6.X)>>
  Typer:  Tom Gee
  Date:   01-03-03 22:08
  Description: Test if Microsoft Visual Studio is correctly configed to use
               Matlab C++ functions. 
*/

#include "matlab.hpp"
#include <ostream>

using namespace std;

static double data0[] = {2, 4, 6, 8};
static double data1[] = {1, 5, 3, 7};

int main(void)
{
    // standard C++ solution.
    int i =0;
    double data2[4];
    for(i = 0; i < 4; ++i)
    {
        data2[i] = (data1[i] + data0[i]) / 2.0;
        cout<< data0[i] << " + " << data1[i] << " = " << data2[i] << endl;
    }
    
    //Matlab solution.
    mwArray mat0(2, 2, data0);
    mwArray mat1(2, 2, data1);
    mwArray mat2;
    
    mat2 = rdivide(plus(mat0, mat1), 2);
    cout<< mat0 << "\t + \n" << mat1 <<"\t/2 = \n" << mat2;
    return(EXIT_SUCCESS);
}
 


Advertisements
Post a comment or leave a trackback: Trackback URL.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: