ITE / code / shared / embedded / KDP / mat_oct / private / kdpeemex.c

    This file is part of "kdpee", kd-partitioning entropy estimator.
    (c) 2008 Dan Stowell and Queen Mary University of London
    All rights reserved.

    kdpee is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    kdpee is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with kdpee.  If not, see <>.

#include "math.h"
#include "mex.h"
#include "kdpee.h"

void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
	const mxArray *xData, *minData, *maxData;
	double *xValues, *mins, *maxs;
	int numdims, numdatums;
	double zcut;

	int *keys;
	const double **dimrefs;
	int i;
	double result;

	if(nrhs < 4){
		mexErrMsgTxt("kdpee error: 4 arguments required by the C implementation.\n");

	// Get info about our input matrix
	xData = prhs[0];
	xValues = mxGetPr(xData); // indexed by whichdim * numdims + whichdatum
	numdims = mxGetN(xData);
	numdatums = mxGetM(xData);
	// mins and maxes
	minData = prhs[1];
	mins = mxGetPr(minData);
	maxData = prhs[2];
	maxs = mxGetPr(maxData);
	if( !(mxGetN(minData)==numdims ||  mxGetN(minData)==numdims)
				|| !(mxGetN(maxData)==numdims ||  mxGetN(maxData)==numdims) ){
    	mexErrMsgTxt("kdpee error: mins and maxs must have same dimension as the # dims in the dataset.\n");
	zcut = mxGetScalar(prhs[3]);
	// Now we allocate space for the keys that we'll need to shuffle around
	keys = mxMalloc(numdatums * sizeof(int));
	// Here we create a set of pointers, one to each row of the input data
	dimrefs = mxMalloc(numdims * sizeof(double*));
	for(i = 0; i < numdims; ++i){
		dimrefs[i] = xValues + (i * numdatums);
	// That's the matlab-specific stuff done, now let's call our calc and return it
	result = kdpee(dimrefs, numdatums, numdims, mins, maxs, zcut, keys);
	plhs[0] = mxCreateDoubleScalar(result);
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.