#include "mex.h" #include /* * Kmeans.c * Kmeans clusters given data into defined number of clusters. * Authors Anu Niemi, Annemari Auvinen */ /* * Initializes the middle points by taking data randomly fom * data array. Same data can be selected only once. * k Number of klusters * n Number of rows in original data matrice * m Number of columns in original data matrice * w Array consisting of the middle points * data Array of the data */ void initialize(int k, int n, int m, double w[], double data[]) { int randNumber, found, j, i, l; int *used; used = mxCalloc(k, sizeof(int)); //Includes used random values for(i=0; i epsilon) { for(i=0; in) mexErrMsgTxt("Number of clusters should be between 0 and the rows in the data matrice"); /* Create the output w and s */ plhs[0] = mxCreateDoubleMatrix(k,m,mxREAL); w = mxGetPr(plhs[0]); plhs[1] = mxCreateNumericMatrix(k,n, mxINT32_CLASS, mxREAL); s = mxGetPr(plhs[1]); kmeans(k, n, m, x, w, s); }