Your basic problem is a misunderstanding of how pointers work in C. Take your z variable for instance:
double *z;
:
z = mxGetPr(plhs[0]);
:
z[i][k] = 0;
The variable z is a "pointer to double". You need to think of it as pointing into a linear array of double values. Since it points to a double, the result of dereferencing it once is a double. E.g., the expression z[i] by itself is a double ... it is not another pointer. So now when you try to apply another dereference with the [k] part, the compiler complains because z[i] is not a pointer so it can't be dereferenced. You can only dereference z once. In other words, you can't use two indexes with z the way you have z defined. You would need to manually calculate the location in memory and use that as a linear subscript. E.g., this would work:
Same comment applies to your x and y variables. You would need to manually calculate an equivalent linear index to use as a single subscript. E.g.
z[i+k*rFirst] = z[i+k*rFirst] + x[i+j*rFirst]*y[j+k*cFirst];
There are ways to use [i][k] subscripting, but you have to define your pointers differently and do some prep work up front to get things to work properly. I will not include that code here but will refer you to this link:
https://www.mathworks.com/matlabcentral/answers/309434-matlab-crashing-when-evaluating-mex
Additionally, you don't have your output dimensions correct. The line
plhs[0] = mxCreateDoubleMatrix(rFirst, cFirst, mxREAL);
should be
plhs[0] = mxCreateDoubleMatrix(rFirst, cSecond, mxREAL);
Also, I will point out that your code will likely crash MATLAB if the inputs are not exactly as expected. I.e., check that there are two inputs and they are each single class matrices and that their inner dimensions agree and that they are not complex. If you were to allow double class inputs, you would need to check that they were not sparse as well. You should put in code to check for those things.
Your second problem is that the author of the MTIMESX submission on the FEX has neglected for some time to get it updated for the newer MATLAB versions and for 64-bit machines. He needs to somehow get access to a newer MATLAB version with a C compiler and find some time to work on that. What MATLAB version are you using, and are you running 32-bit or 64-bit?
Best Answer