Documentation

Real or Imaginary Components Within Complex Arrays

Component Extraction

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];
It is also possible, when calling a method to return or assign a value, to extract only the real or imaginary component of a complex matrix. To do this, call the appropriate component indexing method.

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.

Returning Values Using Component Indexing

The following section illustrates how to return values from full and sparse arrays using component indexing.

Implementing Component Indexing on Full Complex Numeric Arrays

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];

Implementing Component Indexing on Sparse Complex Numeric Arrays (Microsoft Visual Studio 8 and Later)

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];

Assigning Values with Component Indexing

The following section illustrates how to assign values to full and sparse arrays using component indexing.

Implementing Component Indexing on Full Complex Numeric Arrays

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:
                      

Converting MATLAB Arrays to .NET Arrays Using Component Indexing

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.

Converting MATLAB Arrays to .NET Arrays

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);

Converting MATLAB Arrays to .NET Vectors

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);