使用engGetVariable在MATLAB R2014a中检索结构时出错

时间:2014-08-04 15:24:58

标签: c++ c matlab struct

#include <iostream>
#include "engine.h"
using namespace std;

int main(){
    cout << "Start" << endl;
    Engine *ep;
    //Loading Matlab Version R2014a
    if (!(ep = engOpen("/usr/local/MATLAB/R2014a/bin/matlab"))) {
        cout << "\nCan't start MATLAB engine\n";
        return 1;
    } 
    engEvalString( ep, "load('error.mat')" );
    // PHOTOSS_TEMP3 is a struct
    mxArray *K = engGetVariable(ep, "PHOTOSS_TEMP3");
    if(K !=NULL)
        cout << "Loading variable was successful" << endl;
    cout << "End";
    return 0;
}

通过这个示例C ++程序,我试图用MATLAB读取一个结构。但该程序冻结在mxArray *K = engGetVariable(ep, "PHOTOSS_TEMP3");行,我收到错误消息:

Error using save
Can't write file stdio.

这也是makefile:

g++ -I/usr/local/MATLAB/R2014a/extern/include -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"matlab_error.d" -MT"matlab_error.d" -o "matlab_error.o" "matlab_error.cpp"
g++ -Wl,-rpath,/usr/local/MATLAB/R2014a/bin/glnxa64 -L/usr/local/MATLAB/R2014a/bin/glnxa64 -Xlinker -rpath-link -Xlinker /usr/local/MATLAB/R2014a/bin/glnx64 -o "matlab_error"  matlab_error.o   -leng -lmx

和MATLAB文件的“whos”:

Name                       Size            Bytes  Class     Attributes

Custom_Parameters          0x0                 0  double    global    
MultiSignal                1x1             83110  struct              
PHOTOSS_TEMP1              1x1                 8  double              
PHOTOSS_TEMP3              1x1              8210  struct              
Results                    0x0                 0  double    global    
alpha                      1x1                 8  double    global    
beta2                      1x1                 8  double    global    
current_block_no           1x1                 8  double              
fiber_length               1x1                 8  double    global    
main_parameters            1x1              4644  struct    global    
message                    0x0                 0  char      global    
simulation_parameters      1x1              4644  struct     

当我使用MATLAB版本的R2014a Linux时,才会出现此错误。我试过版本2013a / b,它工作正常。当我尝试读取像main_parameters或MultiSignal这样的示例文件的另一个结构时,也会发生这种情况。 那我的错误在哪里?

sample program and matlab file

0 个答案:

没有答案