#include "mex.h"

void mxm(double *x, double *y, double *z, int mx, int nx, int my, int ny) {
	int i,j,k;
	int vz,vx,vy;
	if (nx==my) {
		for (i=0;i<mx;i++) {
			vz=j*mx+i;
			for (j=0;j<ny;j++) {
				*(z+vz) = *(z+vz) + *(x+k*mx+i) * *(y+j*my+k);
			}
		}
	}
}

/*La gateway routine*/
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) {
	double *y, *z, *x;
	int status, mx, nx;
	int my, ny;
	if (nrhs!=2) mexErrMsgTxt("Due input richiesti");
	if (nlhs!=1) mexErrMsgTxt("Un output richiesto");
	/*Matrice di input x*/
	x = mxGetPr(prhs[0]);
	/*Dimensioni della matrice di input x*/
	mx = mxGetM(prhs[0]);
	nx = mxGetN(prhs[0]);
	/*Matrice di input y*/
	y = mxGetPr(prhs[1]);
	my = mxGetM(prhs[1]);
	ny = mxGetN(prhs[1]);
	/*puntatore della matrice di output z*/
	plhs[0] = mxCreateDoubleMatrix(mx,ny,mxREAL);
	/*Crea un puntatore C alla copia della matrice di output*/
	z = mxGetPr(plhs[0]);
	/*Chiama la subroutine C*/
	mxm(x,y,z,mx,nx,my,ny);
}

