Skip to content

Instantly share code, notes, and snippets.

@dbourkey
Created April 11, 2016 22:27
Show Gist options
  • Save dbourkey/c8100318b82756a6f6667125f400a26a to your computer and use it in GitHub Desktop.
Save dbourkey/c8100318b82756a6f6667125f400a26a to your computer and use it in GitHub Desktop.
Creates a 20x20 matrix of randomly generated numbers using a gaussian distribution. Takes mean and standard deviation as input parameters.
#include "mex.h"
#include <random>
void mexFunction(int nlhs, mxArray *plhs[],
int nrhs, const mxArray *prhs[])
{
plhs[0] = mxCreateDoubleMatrix(20, 20, mxREAL);
double *J = mxGetPr(plhs[0]);
double mean = *mxGetPr(prhs[0]);
double dev = *mxGetPr(prhs[1]);
std::default_random_engine generator(time(NULL));
std::normal_distribution<double> distribution(mean, dev);
for (int x = 0; x < 20; x++) {
for (int y = 0; y < 20; y++) {
J[x + 20 * y] = distribution(generator);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment