12 #include <visp3/core/vpMatrix.h> 20 x[0][0] = 1; x[0][1] = 2; x[0][2] = 3;
21 x[1][0] = 4; x[1][1] = 5; x[1][2] = 6;
22 x[2][0] = 7; x[2][1] = 8; x[2][2] = 9;
24 int xCols = x.getCols();
25 int xRows = x.getRows();
32 mxArray *T = mxCreateDoubleMatrix(xRows, xCols, mxREAL);
43 std::cout <<
"ViSP Input Matrix:" << std::endl;
44 for (
size_t i = 0; i < xRows; i++) {
45 for (
size_t j = 0; j < xCols; j++)
46 std::cout << x.data[i * xCols + j] <<
" ";
47 std::cout << std::endl;
52 if (!(ep = engOpen(
""))) {
53 fprintf(stderr,
"\nCan't start MATLAB engine\n");
60 memcpy((
void *)mxGetPr(T), (
void *)x.data, xRows * xCols *
sizeof(
double));
65 engPutVariable(ep,
"Tm", T);
71 engEvalString(ep,
"Dm = sum(Tm');");
76 D = engGetVariable(ep,
"Dm");
81 memcpy((
void *)res, (
void *)mxGetPr(D),
sizeof(res));
85 std::cout << std::endl <<
"MATLAB Output Matrix (Column-wise sum):" << std::endl;
86 for (
size_t i = 0; i < resCols; i++)
87 std::cout << res[i] <<
" ";
88 std::cout << std::endl;
91 std::cout << std::endl <<
"Hit return to quit\n" << std::endl;
98 engEvalString(ep,
"close;");
Implementation of a matrix and operations on matrices.