#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;
}
With this sample C++ program I am trying to read a struct out of MATLAB. But the program freezes in line mxArray *K = engGetVariable(ep, "PHOTOSS_TEMP3"); and i get the error message:
Error using save
Can't write file stdio.
Here is also the 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
and the "whos" of the MATLAB file:
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
This error only appears, when I use the MATLAB version R2014a Linux. I have tried version 2013a/b and it worked fine. It happens also when I try to read another struct of the sample file like main_parameters or MultiSignal. So where is my mistake?