I'm writing a large code that requires me to use a cell array of cell arrays of single precision real matrices. This may seem odd, but there are good reasons centred on efficient storage, that I won't go into here. The simplest code that illustrates the problem that I have is:
#include "mex.h"float fn(mxArray *strat){ float *indstrat, x; indstrat = (float *)mxGetCell(mxGetCell(strat,0),0); x = *(indstrat+1); return x;}void mexFunction(int nlhs, mxArray *plhs[], int nrhs, mxArray *prhs[]){ (void) nlhs; (void) plhs; fn(prhs[0]);}
There's one input, a cell array of cell arrays of the form, for example, strat{i}{j}(k). In this fragment, I've used mxGetCell twice to extract the pointer to the {1}{1} vector, and then extracted the second value from that using '*(indstrat+1)'. However, debugging this in Visual Studio shows that the values aren't being extracted properly. I must be doing something wrong with the pointer to the array of pointers implicit in a cell array like this, but I can't see what. Should there be a '**' somewhere for a pointer to a pointer?
Can anyone tell me what I'm doing wrong?
Best Answer