Using the C++ Math Library    

ExtractScalar( ) and ExtractData( )

ExtractScalar() and ExtractData() provide much safer, though somewhat slower, access to the raw data in an mwArray object. Two versions of ExtractScalar() pull a single scalar from a real or complex array. Three versions of ExtractData() copy the array data into the C++ arrays that you supply.

In the example below, A is an 11-by-11 magic square with a correspondingly sized random complex component. The numerical arguments to ExtractScalar() indicate which scalar to extract; cdata is passed by reference so that it can be modified.

ExtractScalar() treats M-by-N arrays as 1-by-(M*N) vectors. A.ExtractScalar(9) is the first element in the ninth row, or alternatively, the 9th element in the first column; A.ExtractScalar(cdata, 17) is the second element in the sixth row, or alternatively the sixth element in the second column. The two ExtractScalar() functions count down the columns, wrapping from the bottom of the Nth column to the top of the (N+1)th column.


 SetData( ) ToString( )