Storing mxarrays and their elements from a mat file to visual studio map

Hello, im trying to extract variables from a mat File and store their names and their elements in visual studio using map. I've reached to a point where i can read the contents but im not sure how to store them in the map.
#include "mat.h"
#include <iostream>
#include <std_lib_facilities.h>
#include <map>
void main()
{
MATFile *pmat;
const char* name = NULL;
mxArray *pa;
vector<double> v;
map<char, vector<double> > MxArrays_Elements;
/* open mat file and read it's content */
pmat = matOpen("CarMakerSlalom.mat", "r");
if (pmat == NULL)
{
printf("Error Opening File:");
return;
}
/* Read in each array. */
pa = matGetNextVariable(pmat, &name); // I need to find a way to change it to getvariable
while (pa != NULL)
{
mxArray *arr = matGetVariable(pmat, name);
if (arr != NULL && mxIsDouble(arr) && !mxIsEmpty(arr)) {
// copy data
mwSize num = mxGetNumberOfElements(arr);
double *pr = mxGetPr(arr);
if (pr != NULL) {
v.resize(num);
v.assign(pr, pr + num);
}
}
/*
This is where im going to store the name of the Mxarrays and their elements.
*/
//get next variable
pa = matGetNextVariable(pmat, &name);
//destroy allocated matrix
mxDestroyArray(pa);
}
keep_window_open();
matClose(pmat);
}

Answers (0)

Categories

Asked:

on 11 Apr 2016

Community Treasure Hunt

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

Start Hunting!