| Products & Services | Solutions | Academia | Support | User Community | Company |
| Download Product Updates | | | Get Pricing | | | Trial Software |
| Documentation → MATLAB Builder NE |
| Contents | Index |
| Learn more about MATLAB Builder NE |
| On this page… |
|---|
Extracting Real or Imaginary Components Returning Values with Component Indexing Assigning Values with Component Indexing Converting MATLAB Arrays to .NET Arrays Using Component Indexing |
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.
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);
![]() | Dynamically Specifying Run-Time Options to the MCR | Blocking Execution of a Console Application that Creates Figures | ![]() |

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.
| © 1984-2009- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |