source: proiecte/pmake3d/make3d_original/Make3dSingleImageStanford_version0.1/third_party/lightspeed/randbinom.c @ 37

Last change on this file since 37 was 37, checked in by (none), 14 years ago

Added original make3d

File size: 887 bytes
Line 
1/* compile with: cmex bino_sample.c util.o -lm
2 */
3#include "mex.h"
4#include "util.h"
5
6void mexFunction(int nlhs, mxArray *plhs[],
7                 int nrhs, const mxArray *prhs[])
8{
9  int rows, cols, n, i;
10  double *p, *r;
11
12  if(nrhs != 2)
13    mexErrMsgTxt("Usage: r = bino_sample(p, n)");
14
15  /* prhs[0] is first argument.
16   * mxGetPr returns double*  (data, col-major)
17   * mxGetM returns int  (rows)
18   * mxGetN returns int  (cols)
19   */
20  rows = mxGetM(prhs[0]);
21  cols = mxGetN(prhs[0]);
22  p = mxGetPr(prhs[0]);
23  n = (int)*mxGetPr(prhs[1]);
24  if(mxGetM(prhs[1]) != 1 || mxGetN(prhs[1]) != 1)
25    mexErrMsgTxt("n must be scalar");
26
27  if(mxIsSparse(prhs[0]))
28    mexErrMsgTxt("Cannot handle sparse matrices.  Sorry.");
29
30  /* plhs[0] is first output */
31  plhs[0] = mxCreateDoubleMatrix(rows, cols, mxREAL);
32  r = mxGetPr(plhs[0]);
33  for(i=0;i<rows*cols;i++) {
34    *r++ = BinoRand(*p++, n);
35  }
36}
37
Note: See TracBrowser for help on using the repository browser.