31 #include "..\src\persistence1d\persistence1d.hpp" 33 #define NUM_INPUT_VARIABLES 1 34 #define NUM_OUTPUT_VARIABLES 5 35 #define MATLAB_INDEXING true 36 #define NO_FILTERING 0.0 51 bool CheckInput(
const int nOuts, mxArray *outs[],
const int nIns,
const mxArray *ins[]);
63 void mexFunction(
int nlhs, mxArray *plhs[],
int nrhs,
const mxArray *prhs[])
67 std::vector<float>
data;
70 std::vector<int> minIndices;
71 std::vector<int> maxIndices;
72 std::vector<TPairedExtrema> pairs;
81 if (!
CheckInput(nlhs, plhs, nrhs, prhs))
return;
84 mexPrintf(
"Copying input data...\n");
93 mexPrintf(
"Running Persistence1D...\n");
99 mexPrintf(
"Getting results...\n");
108 mexPrintf(
"Done.\n");
109 mexPrintf(
"Writing results to MATLAB...\n");
119 mexPrintf(
"Done.\n");
130 if (mxGetClassID(input) != mxSINGLE_CLASS)
132 mexPrintf (
"Error. Expecting SINGLE value matrix");
136 mwSize numElements = mxGetNumberOfElements(input);
138 inputPt = (
float *)mxGetData(input);
140 data.reserve(numElements);
142 for (
int i = 0; i < numElements; i++)
144 data.push_back((
float)*inputPt++);
154 mxArray * out = mxCreateNumericMatrix(1, 1, mxSINGLE_CLASS, mxREAL);
155 float * mPt = (
float *)mxGetData(out);
172 mxArray * out = mxCreateNumericMatrix(
data.size(), 1, mxSINGLE_CLASS, mxREAL);
173 float * mPt = (
float *)mxGetData(out);
175 for (std::vector<float>::const_iterator pt =
data.begin();
176 pt !=
data.end(); pt++)
190 mxArray * out = mxCreateNumericMatrix(
data.size(), 1, mxSINGLE_CLASS, mxREAL);
191 float * mPt = (
float *)mxGetData(out);
193 for (std::vector<int>::const_iterator pt =
data.begin();
194 pt !=
data.end(); pt++)
207 mxArray * out = mxCreateNumericMatrix(
data.size(), 1, mxSINGLE_CLASS, mxREAL);
208 float * mPt = (
float *)mxGetData(out);
210 for (std::vector<TPairedExtrema>::const_iterator pt =
data.begin();
211 pt !=
data.end(); pt++)
213 *mPt++ = (*pt).Persistence;
233 bool CheckInput(
const int nOuts, mxArray *outs[],
const int nIns,
const mxArray *ins[])
239 mexPrintf(
"\nExpecting one input variables: data vector.");
244 mexPrintf(
"\nExpecting five output variables: MinIndices MaxIndices Persistence GlobalMinIdx GlobalMinVal\n");
247 if (!mxIsNumeric(ins[0]) || mxIsComplex(ins[0]) || !mxIsSingle(ins[0]))
249 mexPrintf (
"\nExpecting the data vector to be REAL, SINGLE, matrix");
253 mwSize dims = mxGetNumberOfDimensions(ins[0]);
256 mexPrintf(
"\nWarning. %d number of dimensions not supported, will handle data as one dimensional data", dims);
260 mrows = mxGetM(ins[0]);
261 ncols = mxGetN(ins[0]);
263 if (mrows!=1 && ncols!=1)
265 mexPrintf(
"\nInput rows: %d cols: %d", mrows, ncols);
266 mexPrintf(
"\nWarning. Expecting one dimensional vector data. Data vector contains: %d %d", mrows, ncols);
278 for (std::vector<float>::const_iterator it =
data.begin();
279 it !=
data.end(); it++)
281 mexPrintf(
"\n data[%d] %f",it-
data.begin(),*it);
bool CheckInput(const int nOuts, mxArray *outs[], const int nIns, const mxArray *ins[])
Validates the following for the input:
#define NUM_OUTPUT_VARIABLES
mxArray * ScalarToMxSingleArray(const float data)
Creates a 1x1 Single Type Matlab matrix from a single float value.
mxArray * VectorToMxSingleArray(const std::vector< float > data)
Copies vector<float> data to 1-d MATLAB matrix.
int GetGlobalMinimumIndex(const bool matlabIndexing=false) const
Returns the index of the global minimum.
bool GetExtremaIndices(std::vector< int > &min, std::vector< int > &max, const float threshold=0, const bool matlabIndexing=false) const
Use this method to get two vectors with all indices of PairedExterma.
#define NUM_INPUT_VARIABLES
bool RunPersistence(const std::vector< float > &InputData)
Call this function with a vector of one dimensional data to find extrema features in the data.
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
Main MATLAB interface.
Finds extrema and their persistence in one-dimensional data.
bool GetPairedExtrema(std::vector< TPairedExtrema > &pairs, const float threshold=0, const bool matlabIndexing=false) const
Use this method to get the results of RunPersistence.
bool MxFloatArrayToFloatVector(const mxArray *input, std::vector< float > &data)
Fills a given float data vector with values from float mxArray.
float GetGlobalMinimumValue() const
Returns the value of the global minimum.
void WriteVectorToMexOutput(const std::vector< float > data)
Displays float-vector content in Matlab output window.
void WriteInputToVector(const mxArray *prhs[], std::vector< float > &data)
Assumption - first input argument is a vector of 1-d data,.