-
Notifications
You must be signed in to change notification settings - Fork 0
/
createDistanceMatrix.c
63 lines (52 loc) · 2.34 KB
/
createDistanceMatrix.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/* ------------------------------------------------------- */
/* */
/* createDistanceMatrix [MATLAB C-MEX] */
/* */
/* ------------------------------------------------------- */
/* */
/* Files: */
/* */
/* createDistanceMatrix.c - MEX interface */
/* distmat.h - function prototypes */
/* distmat.c - function definitions */
/* */
/* See createDistanceMatrix.m for detailed help. */
/* */
/* First version: Aaron Ponti - 02/08/28 */
/* ------------------------------------------------------- */
#include "mex.h"
#include "distmat.h"
void mexFunction(int nlhs, mxArray *plhs[],int nrhs, const mxArray *prhs[])
{
/* Initialize pointers for 2 inputs and 1 output */
double *M, *N;
double *D;
/* Initialize int variables to store matrix dimensions */
int Mrows,Mcols;
int Nrows,Ncols;
/* Check that the number of input and output parameters is valid */
if(nrhs != 2)
mexErrMsgTxt("Two input parameters required.");
if(nlhs > 1)
mexErrMsgTxt("One output parameter required.");
/* Read input parameter dimensions */
Mrows=mxGetM(prhs[0]);
Mcols=mxGetN(prhs[0]);
Nrows=mxGetM(prhs[1]);
Ncols=mxGetN(prhs[1]);
/* Check input parameter dimension */
if ((Mcols>3) || (Ncols>3))
mexErrMsgTxt("Point coordinates in more than 3 dimensions are not supported.");
if (Mcols!=Ncols)
mexErrMsgTxt("The points in the coordinate matrices have different number of dimensions.");
/* Create matrix for the return argument D */
plhs[0]=mxCreateDoubleMatrix(Mrows,Nrows, mxREAL);
/* Assign pointers to each input and output */
M=mxGetPr(prhs[0]);
N=mxGetPr(prhs[1]);
D=mxGetPr(plhs[0]);
/* Call the correcponding C function */
if (Mcols==1) { calcDistMatrix1D(D,M,N,Mrows,Nrows); }
if (Mcols==2) { calcDistMatrix2D(D,M,N,Mrows,Nrows); }
if (Mcols==3) { calcDistMatrix3D(D,M,N,Mrows,Nrows); }
}