~nipy-developers/nipy/fff2

« back to all changes in this revision

Viewing changes to matlab/fffMat_quantile.c

  • Committer: Bertrand THIRION
  • Date: 2008-04-03 17:29:55 UTC
  • mfrom: (13.1.5 fff2)
  • Revision ID: bt206016@is143015-20080403172955-w7v1pdjdriofvzzs
Merged Alexis'changes

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include "fffMat.h"
 
2
 
 
3
#include <fff_routines.h>
 
4
 
 
5
/* 
 
6
   
 
7
Y = fffMat_quantile( X, P )
 
8
 
 
9
X : two-dimensional array 
 
10
P : value between 0 and 1 
 
11
 
 
12
 
 
13
*/ 
 
14
 
 
15
void mexFunction( int nlhs, mxArray *plhs[], 
 
16
                  int nrhs, const mxArray*prhs[] )
 
17
 
18
  /* Variables */ 
 
19
  gsl_vector **X; 
 
20
  gsl_vector *Y; 
 
21
  gsl_vector *aux; 
 
22
  double P; 
 
23
  int i, nvox, flagInterp = 0; 
 
24
 
 
25
  /* Check for proper number of arguments. */
 
26
  if ( nrhs < 2 ) {
 
27
    mexErrMsgTxt("Two input arguments required.");
 
28
  } 
 
29
  else if ( nlhs > 1 ) 
 
30
    mexErrMsgTxt("Too many output arguments");
 
31
 
 
32
 
 
33
  /* Parse input */
 
34
  X = gsl_vector_list_from_mxArray_new( prhs[0], &nvox );
 
35
  P = *mxGetPr( prhs[1] );
 
36
  if ( nrhs > 2 ) 
 
37
    flagInterp = (int) ( *mxGetPr( prhs[2] ) ); 
 
38
 
 
39
  /* Allocate output */ 
 
40
  plhs[0] = mxCreateDoubleMatrix( 1, nvox, mxREAL );
 
41
  Y = gsl_vector_from_mxArray( plhs[0] );
 
42
  
 
43
  /* Local variables */ 
 
44
  aux = gsl_vector_alloc( X[0]->size ); 
 
45
  
 
46
  /* Loop over voxels */ 
 
47
  for( i=0; i<nvox; i++ ) {
 
48
    gsl_vector_memcpy( aux, X[i] ); 
 
49
    gsl_vector_set ( Y, i, fff_quantile_from_temp_data( aux, P, flagInterp ) ); 
 
50
  }
 
51
 
 
52
 
 
53
  /* Free memory */ 
 
54
  gsl_vector_list_from_mxArray_delete( X, nvox );
 
55
  gsl_vector_free( Y ); 
 
56
  gsl_vector_free( aux ); 
 
57
 
 
58
  return; 
 
59
}
 
60