1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
|
#include "mex.h"
#include "math.h"
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
void CircMex(float **, int, int, int, int, int, float);
void mexFunction(
int nlhs, mxArray *plhs[],
int nrhs, const mxArray *prhs[]) {
int centerx, centery, radius;
float **data, Isig;
mwSize M, N;
M = (mwSize)mxGetScalar(prhs[0]);
N = (mwSize)mxGetScalar(prhs[1]);
centerx = (int)mxGetScalar(prhs[2]);
centery = (int)mxGetScalar(prhs[3]);
radius = (int)mxGetScalar(prhs[4]);
Isig = (float)mxGetScalar(prhs[5]);
plhs[0] = mxCreateNumericMatrix(M, N, mxSINGLE_CLASS, mxREAL);
data = mxGetData(plhs[0]);
CircMex(data, N, M, centerx, centery, radius, Isig);
}
void CircMex(float **data, int N, int M, int centerx, int centery, int radius,float Isig)
{
int n,m;
float temp;
for(n=0;n<=N-1;n++)
{
for(m=0;m<=M-1;m++)
{
temp=sqrt(pow((double)((n-N/2)-centerx),2)+pow((double)((m-M/2)-centery),2));
if(temp<=radius)
{
data[n][m]=Isig;
}
else
data[n][m]=0;
}
}
} |