2015-02-07 163 views
0

我必須編寫C++代碼,它接受來自MatLab的幾個矩陣,分析這些矩陣並輸出單個矩陣。在分析中的代碼已經編寫,所有的矩陣和變量的聲明在一個類可以稱之爲類MMclassMex C++類函數聲明

class MMclass { 

    public: 

    // Start point of the application 
    int inici(void);   

    #ifdef _WIN32 
     ... 
    #elif linux 
     ... 
    #endif 

    private:   

    // Variables ------------------------------------------- 

    // Private methods ------------------------------------------- 
    ... 
    void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]); 
    ... 
}; 

大部分代碼已經編寫完成,我只是試圖添加的mexFunction to increase the efficiency。正因爲如此,我希望能夠用

void MMclass::mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) 
{ 
    ... 
} 

訪問和修改在也使用該代碼的其餘部分原來的類聲明的變量。我無法弄清楚如何在MMclass中聲明mexFunction以允許它工作。 mexFuntion在read.cpp中找到,我正在使用mex read.cpp進行編譯。我試圖改爲使用結構並傳遞該結構,但更改所有預先編寫的代碼非常繁瑣。

+1

目前尚不清楚您打算如何使用庫並實例化類,但MATLAB查找單個入口點:從庫中導出的全局名稱空間函數'mexFunction'。僅僅因爲'MMclass'有一個名爲'mexFunction'的方法並不能訪問它。你需要持久的內存嗎?你想解決什麼問題? – chappjc 2015-02-07 05:41:10

+0

有一個名爲MMclass的以前聲明的類,該類及其變量用於其餘代碼中。我希望mexFunction入口點能夠從MatLab中獲取值,並相應地在MMclass中更改這些變量的值。我已經設法分別提取每個矩陣並具有確切的格式。我所需要的只是能夠將這些變量從mexFunction複製到類中,以便程序的其餘部分可以使用這些變量。 – 2015-02-07 05:50:38

+0

你還沒有解釋你如何計劃這個類的實例來生成。如果還有另一個進程(即除了正在運行並具有此類的MATLAB之外的可執行文件),則不能將數據注入到這樣的其他進程中。如果你想使用這個類,然後編寫一個'mexFunction'來創建這個類,並添加一個方法來處理它的成員變量。 – chappjc 2015-02-07 07:07:44

回答

0
class MMclass { 

    public: 

    // Start point of the application 
    int inici(void);   

    #ifdef _WIN32 
     ... 
    #elif linux 
     ... 
    #endif 

    private:   

    // Variables ------------------------------------------- 

    // Private methods ------------------------------------------- 
    ... 

    ... 
}; 

void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) 
{ 
    MMclass YourClassInstance; 

}