Hello, I am trying to link this simple matlab script
A = [2 3; -1 4];B = [5; 3];C = zeros(2, 1);alpha = 1;beta = 1;C = mv_mult(A, B, alpha, beta)
with the following mexFunction
#include "stdio.h"#include "stdlib.h"#include "string.h"#include "blas.h"#include "mex.h"#include "matrix.h"void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) { /* pointers to input & output matrices*/ double *A, *v, *Y, *a, *b; ptrdiff_t rows_A, cols_A; ptrdiff_t rows_v, cols_v; // create input matrix (A) A = mxGetDoubles(prhs[0]); rows_A = mxGetM(prhs[0]); cols_A = mxGetN(prhs[0]); // create input vector (v) v = mxGetDoubles(prhs[1]); rows_v = mxGetM(prhs[1]); cols_v = 1; // parse scalars (a, b) a = mxGetDoubles(prhs[2]); b = mxGetDoubles(prhs[3]); // create output matrix (Y) plhs[0] = mxCreateDoubleMatrix(rows_A, cols_v, mxREAL); Y = mxGetPr(plhs[0]); printf("A[0]: %lf\n", A[0]); printf("A[1]: %lf\n", A[1]); // compute mm multiplication using blas2 operations char chn = 'N'; const long int i_one = 1; dgemv_(&chn, &rows_A, &cols_A, a, A, &cols_v, v, &i_one, b, Y, &i_one);}
The function compiles without errors nor warnings but matlab replies with [0 0]' instead of [19 7]'. I can't understand why though. Note that I am trying to use blas2 operations only.
Best Answer