From: James Tursa on
"Ehsan Salari" <ehsan.salari(a)gmail.com> wrote in message <hqkqi6$j5j$1(a)fred.mathworks.com>...
> I am trying to open a mat file in C++. In my mat file I have arrays of type double and integer and also numbers. I use the following piece of code:
>
> MATFile *pmat = matOpen(filename.c_str(), "r");
> mxArray *pa = matGetVariable(pmat, "bixe");
> if (pa == NULL) {
> printf("Error reading bixe\n");
> }
> int *myVector = (int *)mxGetData(pa);
>
> Now for some reason myVector is just a vector of zeros. However if I do the following, there is no problem:
>
> double *myVector = (double *)mxGetData(pa);
>
> In the latter case, I get the right values but in double format. Would you please let me know why the former does not work?

Offhand I would have to say that variable bixie in the mat file is in fact of type double, so that is what you got when you read it. Why do you think it should be otherwise? Did you intend to originally save it in the mat file as an int32 class variable?

James Tursa