Multidimensional matrix multiplication with mex
Show older comments
Hi
I am trying to do matrix multiplication via Mex.
#include "mex.h"
void mexFunction( int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) {
float *x;
float *y;
double *z;
mwSize rFirst, cFirst, cSecond;
x = mxGetData(prhs[0]);
y = mxGetData(prhs[1]);
rFirst = mxGetM(prhs[0]);
cFirst = mxGetN(prhs[0]);
cSecond = mxGetN(prhs[1]);
plhs[0] = mxCreateDoubleMatrix(rFirst, cFirst, mxREAL);
z = mxGetPr(plhs[0]);
int i;
int j;
int k;
for(k = 0; k <= cSecond - 1 ; k++) {
for(i = 0; i <= rFirst - 1 ; i++) {
z[i][k] = 0;
for(j = 0; j <= cFirst - 1; j++) {
z[i][k] = z[i][k] + x[i][j]*y[j][k];
}
}
}
}
When i try and implement this i get the error:
> mex matrixMultiplication.c
error: subscripted value is neither array nor pointer
I then tried changing the script to:
float **x;
float **y;
double **z;
But that results in:
> mex matrixMultiplication.c
warning: assignment from incompatible pointer type
Does anyone know how to fix this?
Here is an extra question: I tried importing a mex file from File Exchange: mTimesx. I unzipped the folder and placed the content in my working directory. I then tried initializing it (Or what you call it).
> mex mTimesx.c
undefined reference to 'foobar'
I got this error many many times. How do you import a C-mex file correctly?
Hope someone knows the answers to these things :) Thanks in advance!!
Accepted Answer
More Answers (0)
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!