When you access a complex array (an array made up of both real and imaginary data), you extract both real and imaginary parts (called components) by default. This method call, for example, extracts both real and imaginary components:
MWNumericArray complexResult= complexDouble[1, 2];
This section describes how to use component indexing when returning
or assigning a value, and also describes how to use component indexing
to convert MATLAB® arrays to .NET arrays using the ToArray
or ToVector
methods.
The following section illustrates how to return values from full and sparse arrays using component indexing.
To return the real or imaginary component from a full complex
numeric array, call the .real
or .imaginary
method
on MWArrayComponent
as follows:
complexResult= complexDouble[MWArrayComponent.Real, 1, 2]; complexResult= complexDouble[MWArrayComponent.Imaginary, 1, 2];
To return the real or imaginary component of a sparse complex
numeric array, call the .real
or .imaginary
method MWArrayComponent
as
follows:
complexResult= sparseComplexDouble[MWArrayComponent.Real, 4, 3]; complexResult = sparseComplexDouble[MWArrayComponent.Imaginary, 4, 3];
The following section illustrates how to assign values to full and sparse arrays using component indexing.
To assign the real or imaginary component to a full complex
numeric array, call the .real
or .imaginary
method MWArrayComponent
as
follows:
matrix[MWArrayComponent.Real, 2, 2]= 5; matrix[MWArrayComponent.Imaginary, 2, 2]= 7:
The following section illustrates how to use the ToArray
and ToVector
methods
to convert full and sparse MATLAB arrays and vectors to .NET
arrays and vectors respectively.
To convert MATLAB arrays to .NET arrays call the toArray
method
with either the .real
or .imaginary
method,
as needed, on MWArrayComponent
as follows:
Array nativeArray_real= matrix.ToArray(MWArrayComponent.Real); Array nativeArray_imag= matrix.ToArray(MWArrayComponent.Imaginary);
To convert MATLAB vectors to .NET vectors (single dimension
arrays) call the .real
or .imaginary
method,
as needed, on MWArrayComponent
as follows:
Array nativeArray= sparseMatrix.ToVector(MWArrayComponent.Real); Array nativeArray= sparseMatrix.ToVector(MWArrayComponent.Imaginary);