mxArray dynamic memory allocation

조회 수: 1 (최근 30일)
Fabian Jonsson
Fabian Jonsson 2013년 12월 19일
I want to read a struct (called ROAD) from a .mat file and create a map<string,double> from it so that the map is a reflection of the ROAD. The fields in the Matlab struct are arrays of different lengths, and this is the current state of the code.
I have a string vector called ROAD_fields that are just a list of the field names of the matlab struct. I also have a map<string,double> called ROAD that I want to fill.
std::vector<std::string> *ROAD_fields;
std::map<std::string, double> ROAD;
Here is the implementation so far:
void Road::getRoadFromFile() {
MATFile *file = matOpen(this->filename.c_str(),"r");
mxArray *roadstruct = matGetVariable(file, "ROAD");
int i;
mxArray* field;
for(i=0; i<this->ROAD_fields->size(); i++) {
field = mxGetFieldByNumber(roadstruct,0,i);
this->ROAD[this->ROAD_fields->at(i).c_str()] = this->extractField(field);
}
};
double Road::extractField(mxArray *ptr) {
return *(double*) mxGetPr(ptr);
};
I get an access violation in the extractField call and I guess it's due to the fact that the arrays have different lengths? I think I need to reallocate memory somehow, but I haven't been able to figure out how.
Please help!

답변 (0개)

카테고리

Help CenterFile Exchange에서 Deploy to C++ Applications Using MATLAB Data API (C++11)에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by