#include "mclcppclass.h"
int main(){
if (!mclInitializeApplication(NULL,0))
{ std::cerr << "could not initialize the library properly"<<std::endl;
return -1;
}
try
{ int x,y;
int* a = NULL;
int* b = NULL;
std::cout << "Enter length of array 1:" <<std::endl;
std::cin >> x; // Create input data
std::cout << "Enter length of array 2:" <<std::endl;
std::cin >> y;
a = new int[x]; // Allocate x ints and save ptr in a.
b = new int[y]; // Allocate y ints and save ptr in b.
for (int i=0; i<x; i++) {
a[i] = i; // Initialize all elements in increments of 1.
}
for (int j=0; j<y; j++) {
b[j] = 1; // Initialize all elements to one.
}
mwArray in1(1, x, mxDOUBLE_CLASS, mxREAL);
mwArray in2(1, y, mxDOUBLE_CLASS, mxREAL);
in1.SetData(a, x);
in2.SetData(b, y);
std::cout << "The 1st array is:" << std::endl;
std::cout << in1 << std::endl;
std::cout << "The 2nd array is:" << std::endl;
std::cout << in2 << std::endl;
delete [] a; //When done free memory pointed to by a.
a = NULL;
delete [] b;
b = NULL; //When done, free memory pointed to by b.
}
catch (const mwException& e)
{ std::cerr << e.what() << std::endl;
return -1;
}
catch (...
{ std::cerr << "Unexpected error thrown" << std::endl;
return -1;
}
mclTerminateApplication();
return 0;
}
Best Answer