The Math Forum

Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Math Forum » Discussions » Software » comp.soft-sys.matlab

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: trouble using mxGetData for int array
Replies: 2   Last Post: Dec 23, 2013 1:29 PM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Bruce Elliott

Posts: 127
Registered: 11/9/07
trouble using mxGetData for int array
Posted: Dec 18, 2013 3:08 PM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

I am setting values in mxArray structure that is the output of a MEX file. Some of the structure fields are arrays of floats and others are arrays of ints (I can't control this; the source data is from 3rd party library functions).

I use this code to set the values for arrays of floats:

mxArray *pFieldValue;
float *pfloat;
int *pint;
mwSize nrows, ncols;
int ridx, cidx;

nrows = 1;
ncols = 3;
pFieldValue = mxCreateNumericMatrix(nrows,ncols,mxSINGLE_CLASS,mxREAL);
pfloat = (float*)mxGetData(pFieldValue);
for (ridx=0; ridx<nrows; ridx++) {
for (cidx = 0;cidx<ncols;cidx++) {
pfloat[ridx,cidx] = <some float value>;

which compiles just fine. I have the following block for arrays of ints:

nrows = 1;
ncols = 1;
pFieldValue = mxCreateNumericMatrix(nrows,ncols,mxINT32_CLASS,mxREAL);
pint = (int*)mxGetData(pFieldValue);
for (ridx=0; ridx<nrows; ridx++) {
for (cidx = 0; cidx<ncols;cidx++) {
pint[ridx,cidx] = <some int value>;

but the compiler complains about the line with pint[ridx,cidx] with the message:

error C2109: subscript requires array or pointer type

The two blocks of code look the same to me, other than the pointers to ints vs. pointers to floats. (I know the matrix of ints is 1-by-1, but the compiler shouldn't care about that, right?)

Can anyone tell me why the second one does not work?

Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© The Math Forum at NCTM 1994-2018. All Rights Reserved.