#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <matrix.h>
#include <engine.h>
#include <visp3/core/vpMatrix.h>
int main()
{
x[0][0] = 1; x[0][1] = 2; x[0][2] = 3;
x[1][0] = 4; x[1][1] = 5; x[1][2] = 6;
x[2][0] = 7; x[2][1] = 8; x[2][2] = 9;
Engine *ep;
mxArray *T = mxCreateDoubleMatrix(xRows, xCols, mxREAL);
mxArray *D = NULL;
double res[3];
int resCols = 3;
std::cout << "ViSP Input Matrix:" << std::endl;
for (size_t i = 0; i < xRows; i++) {
for (size_t j = 0; j < xCols; j++)
std::cout << x.
data[i * xCols + j] <<
" ";
std::cout << std::endl;
}
if (!(ep = engOpen(""))) {
fprintf(stderr, "\nCan't start MATLAB engine\n");
return EXIT_FAILURE;
}
memcpy((
void *)mxGetPr(T), (
void *)x.
data, xRows * xCols *
sizeof(
double));
engPutVariable(ep, "Tm", T);
engEvalString(ep, "Dm = sum(Tm');");
D = engGetVariable(ep, "Dm");
memcpy((void *)res, (void *)mxGetPr(D), sizeof(res));
std::cout << std::endl << "MATLAB Output Matrix (Column-wise sum):" << std::endl;
for (size_t i = 0; i < resCols; i++)
std::cout << res[i] << " ";
std::cout << std::endl;
std::cout << std::endl << "Hit return to quit\n" << std::endl;
fgetc(stdin);
mxDestroyArray(T);
mxDestroyArray(D);
engEvalString(ep, "close;");
engClose(ep);
return EXIT_SUCCESS;
}