Re: Kmeans using mexCallMATLAB
- From: Peter Boettcher <boettcher@xxxxxxxxxx>
- Date: Mon, 17 Jul 2006 16:14:01 -0400
"nils" <nilshomer@xxxxxxxxx> writes:
I want to perform kmeans clustering on an array of values that I pass
into the function below. MATLAB crashes during the call mexCallMATLAB
for kmeans. Any help would be greatly appreciated.
/* Takes in an array of values and performs kmeans clustering on the
values and stores the output in the mxOutput array */
void kmeans(int * values, int num_values, mxArray * mxOutput)
{
int num_input_args = 2;
int num_output_args = 1;
int i;
int colLen = 2;
int rowLen = num_values;
double * doubleValues;
mxArray * input_args[2];
mxArray * num_clusters;
mxArray * mxValues;
input_args[0] = mxValues;
^ Right here, mxValues is garbage. That garbage is copied to
input_args[0].
/* Set up the number of cluster to compute */
num_clusters = mxCreateNumericMatrix(1, 1, mxDOUBLE_CLASS, mxREAL);
(mxGetPr(num_clusters))[0] = NUM_KMEANS_CLUSTERS;
input_args[1] = num_clusters;
/* Set up the data to pass to kmeans */
mxValues = mxCreateDoubleMatrix(num_values, colLen, mxREAL);
^ Now you reassign mxValues to point to something real.
doubleValues = mxGetPr(mxValues);
for(i=0;i<rowLen;i++) {
doubleValues[i]= values[i];
doubleValues[i+rowLen] = 0;
}
mexCallMATLAB(num_output_args, &mxOutput, num_input_args,
input_args, "kmeans");
^ Now you call MATLAB with the input_args[0], which still has the
original garbage.
--
Peter Boettcher <boettcher@xxxxxxxxxx>
MIT Lincoln Laboratory
MATLAB FAQ: http://www.mit.edu/~pwb/cssm/
.
- References:
- re: Kmeans using mexCallMATLAB
- From: nils
- re: Kmeans using mexCallMATLAB
- Prev by Date: re: Kmeans using mexCallMATLAB
- Next by Date: Re: Printing Matlab Figures
- Previous by thread: re: Kmeans using mexCallMATLAB
- Next by thread: Working with Large data files.
- Index(es):
Relevant Pages
|