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.
mwArray A = magic(11) + (rand(11) * i()); double rdata, cdata; rdata = A.ExtractScalar(9); // Real part only rdata = A.ExtractScalar(cdata, 17); // Real and complex part int32 *integers = new int32[ 11 * 11 ]; A.ExtractData(integers); // Cast doubles to integers double *real_data = new double [ 11 * 11 ]; double *complex_data = new double [ 11 * 11 ]; A.ExtractData(real_data); // Real part only A.ExtractData(real_data, complex_data); // Real and complex part
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( ) | ![]() |