MxSetBlock question

hi, I am working with the matrix that is returned from the PriceVolumeDistribution

I extract the volume and price from the matrix using:

rows = MxGetSize( mxVolb, 0 );
volb = MxGetBlock( mxVolb, 0, rows - 1, 1, 1, True );
prcb = MxGetBlock( mxVolb, 0, rows - 1, 0, 0, True );

then I create a second matrix in wich I want to keep the price column (column 0 ) but store something else in column 1

so I create the matrix:

mxVolb_imb = Matrix( rows, 2, 0 );

then I want to put the price array back in column 0 of the newly created matrix. I use:

MxSetBlock( mxVolb_imb, 0, rows - 1, 0, 0, prcb );

but I get zeros. I know the prcb array is filled correctly because this works:

            for( xx = 0; xx < rows - 1; xx++ )
            {
                mxVolb_imb[xx][0] = prcb[xx];
            }

why does

MxSetBlock( mxVolb_imb, 0, rows - 1, 0, 0, prcb );

not work? Thanks

By default all arguments are passed by value (which means that arguments are not modified by function). Therefore
MxSetBlock RETURNS modified matrix, so you have to do ASSIGNMENT:

// must assign result
mxVolb_imb = MxSetBlock( mxVolb_imb, 0, rows - 1, 0, 0, prcb );

By the way in the guide AFL Function Reference - MXSETBLOCK there is a note:

Note: the function creates new matrix as a result (so source matrix is unaffected unless you do the assignment of the result back to the original variable)

2 Likes

thank you, will try that

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.