Menu

Trouble with data when reading many variables

Anonymous
2013-01-15
2013-05-30
  • Anonymous

    Anonymous - 2013-01-15

    Hi! First I'd like to thank for this great project.

    I'm currently trying to read many variables at once, so I can use them in the rest of my code, like this:

    matvar_t *var_x = Mat_VarRead(matfp, "x");
    matvar_t *var_y = Mat_VarRead(matfp, "y");
    matvar_t *var_z = Mat_VarRead(matfp, "z");
    

    But when I try to access the data of these variables, only the first one, var_x->data, is accessible. The other pointers indicate:
    "data 0x00000000 void*" in the watch.

    Is there a way I can do this?

     
  • cch

    cch - 2013-01-16

    There is nothing wrong with what you typed and I regularly load multiple variables at once. Make sure the MAT file has all of those variables and they are not empty. Also, make sure that you execute those lines in the debugger. Sometimes with optimizations it is not clear if lines have executed or not. Empty variables may have a data pointer of NULL.

     
  • Anonymous

    Anonymous - 2013-01-16

    Hi! Thanks for the fast response.

    I'm sorry, but there must be something wrong. Even if I code like this:

    matvar_t *var_x = Mat_VarRead(matfp, "x");
    matvar_t *var_y = Mat_VarRead(matfp, "x");
    matvar_t *var_z = Mat_VarRead(matfp, "x");
    

    Only var_x->data is a valid pointer. The others are 0x00000000. I ran those lines in the debugger. As the variables are 88 million sized double arrays, it takes a while when I run the first line, but the other two execute really fast.

    The mat file version is 4 and I run in VisualStudio 2012, I don't know if that helps.

    I noticed that after I use Mat_VarRead a first time, the next times will have variables with invalid values as *data.

    Please, is there any way I can work this around?

     
  • Anonymous

    Anonymous - 2013-01-18

    Ok, i noticed that if I do the following:

    //VarX
    matvar_t *matvar = Mat_VarRead(matfp, "x");
    //Code..
    Mat_VarFree(matvar); 
    matvar = NULL;
    //VarY
    matvar_t *matvar = Mat_VarRead(matfp, "y");
    //Code...
    Mat_VarFree(matvar); 
    matvar = NULL;
    

    I can acces the data pointer of both variables "x" and "y" in matlab. But I really need to have access to both of them at the same time, because I proccess them at the same time in a very long loop. And the only way to read both is doing as I mentioned above.

    Could it be a problem in version 1.5.0?

     
  • Anonymous

    Anonymous - 2013-01-19

    Hi.
    This discussion can be closed. I figured out that the 3rd variable wasn't getting its value simply because it was exceeding the max memory available for the proccess.
    Thanks!

     
  • Cecilia

    Cecilia - 2013-02-19

    what is actually the maximum number of rows and columns that can be put in the array? Is it dependent on the system resources, or is there also a techinical limitation?

     

Log in to post a comment.