C++ 함수와 관련 mex를 작성합니다. 그러나 C++ 함수의 한 종류의 입력은 double *
입니다.오류가 'void *'에서 'float *'로 변환 될 수 없습니다.
기능
pointwise_search
의 출력은 포인터입니다. 나는 그것을 삭제해야한다고 들었다. 그러나 출력으로 필요하기 때문에 어디에서 삭제해야하는지 모르겠습니다.대답에서 나는 입력 유형을
mxIsSingle
으로 확인해야한다는 것을 알고 있습니다. 그래서 함수를 수정합니다mexFunction
. 그러나 오류error C2440: '=' : cannot convert from 'void *' to 'float *'
이 있습니다.매트랩, I는
pointwise_search(
플로트 * 피,
플로트 Q, num_thres,
플로트, len)
N 형 호한다. 만약 내가 벡터 v_in_matlab = rand (5,1) matlab에있다. 나는 그것이p=single(v_in_matlab);
에 의해 포인터와 사전에 다음pointwise_search(p...
감사 받아야합니다.
#include "mex.h"
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
using namespace std;
float * pointwise_search(float *p,float *q,int num_thres, float* n, int len)
{
vector<float> P(p, p + num_thres);
vector<float> Q(q, q + num_thres);
int size_of_threshold = P.size();
float *Y=new float[len];
float *z=new float[len];
typedef vector<float > ::iterator IntVectorIt ;
IntVectorIt start, end, it, location ;
start = P.begin() ; // location of first
// element of Numbers
end = P.end() ; // one past the location
// last element of Numbers
for (int i=0;i<len;i++)
{
location=lower_bound(start, end, n[i]) ;
z[i]=location - start;
if(z[i]>0&&z[i]<size_of_threshold)
{
Y[i]=(n[i]-P[z[i]])/(P[z[i]-1]-P[z[i]])*(Q[z[i]-1]-Q[z[i]])+Q[z[i]];
}
else
{
Y[i]=Q[z[i]];
}
}
return (&Y[0]);
}
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
float * Numbers, *Q;
if (nrhs != 5)
{
mexErrMsgTxt("Input is wrong!");
}
float *n = (float*) mxGetData(prhs[3]);
int len = (int) mxGetScalar(prhs[4]);
int num_thres = (int) mxGetScalar(prhs[2]);
/* Input gs */
if(mxIsComplex(prhs[0])
||!mxIsSingle(prhs[0]))
mexErrMsgTxt("Input 0 should be a class Single");
/* get the pointer to gs */
Numbers=mxGetData(prhs[0]);
if(mxIsComplex(prhs[0])
||!mxIsSingle(prhs[0]))
mexErrMsgTxt("Input 0 should be a class Single");
/* get the pointer to gs */
Q=mxGetData(prhs[1]);
// float * Numbers= (float *)mxGetData(prhs[0]);
// float * Q= (float *)mxGetData(prhs[1]);
float * out= pointwise_search(Numbers,Q,num_thres,n,len);
//float* resizedDims = (float*)mxGetPr(out);
}
귀하의 의견에 감사드립니다. 'pointwise_search' 함수의 출력 'Y'를 어디에서 삭제해야하는지 말해 주시겠습니까? – Vivian