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