Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/matlab/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
错误无法从';void*';至';浮动*'` 我写了C++函数及其相关的MEX。C++函数的一种输入是:代码>双*< /代码>。_C++_Matlab_Mex - Fatal编程技术网

错误无法从';void*';至';浮动*'` 我写了C++函数及其相关的MEX。C++函数的一种输入是:代码>双*< /代码>。

错误无法从';void*';至';浮动*'` 我写了C++函数及其相关的MEX。C++函数的一种输入是:代码>双*< /代码>。,c++,matlab,mex,C++,Matlab,Mex,函数逐点搜索的输出是指针。有人告诉我应该删除它。但是我不知道应该在哪里删除它,因为我需要它作为输出 从答案中,我知道我应该通过mxisingle检查输入类型。因此,我更正了函数mexFunction。但有一个错误错误C2440:“=”:无法从“void*”转换为“float*” 在matlab中,我应该调用likepointwise\u search(float*p,float q,num\u thres,float n,len)。如果我在matlab中有一个向量v_=rand(5,1)。我应该

  • 函数
    逐点搜索的输出是指针。有人告诉我应该删除它。但是我不知道应该在哪里删除它,因为我需要它作为输出

  • 从答案中,我知道我应该通过
    mxisingle
    检查输入类型。因此,我更正了函数
    mexFunction
    。但有一个错误
    错误C2440:“=”:无法从“void*”转换为“float*”

  • 在matlab中,我应该调用like
    pointwise\u search(
    float*p
    float q
    ,num\u thres,
    float n
    ,len)
    。如果我在matlab中有一个向量v_=rand(5,1)。我应该通过
    p=single(matlab中的v_)得到它的指针然后
    逐点搜索(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);
    }
    
    #包括“mex.h”
    #包括
    #包括
    #包括
    #包括
    使用名称空间std;
    浮点*逐点搜索(浮点*p,浮点*q,整数,浮点*n,整数)
    {
    向量P(P,P+num_-thres);
    向量Q(Q,Q+num_-thres);
    int size_of_threshold=P.size();
    浮动*Y=新浮动[len];
    float*z=新的float[len];
    typedef向量::迭代器IntVectorIt;
    IntVectorIt开始、结束、it、位置;
    start=P.begin();//第一个
    //数元素
    end=P.end();//超过该位置一个
    //数的最后一个元素
    
    对于(int i=0;i0&z)i(p>),在Matlab中使用<代码>单()>代码>在调用MeXEffic之前对数据进行转换。C++侧验证该类型确实是由代码> MxISSIN()构成的。<>代码>之后,你可以愉快地转换到<代码>浮点*

    < P>在你担心你的MEX代码之前,先看一下你的C++函数。你有一些非常明显的(<代码>新的< /代码>,但是没有<代码>删除[]/COD>)。 关于MEX,您不应该看到:

    (float *)mxGetPr(prhs[0])
    
    您不能将
    double*
    转换为
    float*
    并期望数字有任何意义。从MATLAB中输入
    single
    ,然后使用:

    (float *)mxGetData(prhs[0])
    

    并按照Triarion的建议进行操作,并测试所有输入
    mxArray
    s的预期数据类型。

    谢谢您的评论。您能告诉我应该在哪里删除函数
    逐点搜索的输出
    Y