diff toolboxes/FullBNT-1.0.7/KPMtools/normaliseC.c @ 0:cc4b1211e677 tip

initial commit to HG from Changeset: 646 (e263d8a21543) added further path and more save "camirversion.m"
author Daniel Wolff
date Fri, 19 Aug 2016 13:07:06 +0200
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/toolboxes/FullBNT-1.0.7/KPMtools/normaliseC.c	Fri Aug 19 13:07:06 2016 +0200
@@ -0,0 +1,29 @@
+/* C mex version of normalise.m in misc directory  */
+
+#include "mex.h"
+
+void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
+{
+  double *T, *sum_ptr, sum;
+  int i, N;  
+
+  plhs[0] = mxDuplicateArray(prhs[0]);
+  T = mxGetPr(plhs[0]);
+  if(mxIsSparse(plhs[0])) N = mxGetJc(plhs[0])[mxGetN(plhs[0])];
+  else N = mxGetNumberOfElements(plhs[0]);
+
+  plhs[1] = mxCreateDoubleMatrix(1, 1, mxREAL);
+  sum_ptr = mxGetPr(plhs[1]);
+
+  sum = 0;
+  for (i = 0; i < N; i++) {
+    sum += *T++;
+  }
+  T = mxGetPr(plhs[0]);
+  if (sum > 0) {
+    for (i = 0; i < N; i++) {
+      *T++ /= sum;
+    }
+  } 
+  *sum_ptr = sum;
+}