ComplexMatrixItem Property (Int32, String) |
Namespace: Novacta.Analytics
Exception | Condition |
---|---|
ArgumentNullException | columnIndexes is null. -or- value is null. |
ArgumentOutOfRangeException | rowIndex is
less than zero. -or- rowIndex is greater than or equal to the number of rows of this instance. -or- columnIndexes is not a string reserved for tabular collection sub-referencing. |
ArgumentException |
The number of rows in value is greater than 1. -or- The number of columns in value is not equal to the number of columns of this instance. |
When setting elements simultaneously, the value must be a tabular collection having a number of rows equal to the number of specified row indexes, and a number of columns equal to the number of specified column indexes.
In the following example, some matrix elements are simultaneously accessed.
using System; using System.Numerics; namespace Novacta.Analytics.CodeExamples { public class ComplexMatrixIndexerExample02 { public void Main() { // Create a matrix. var data = new Complex[8] { new Complex(1, -1), new Complex(5, -5), new Complex(2, -2), new Complex(6, -6), new Complex(3, -3), new Complex(7, -7), new Complex(4, -4), new Complex(8, -8) }; var matrix = ComplexMatrix.Dense(4, 2, data, StorageOrder.RowMajor); Console.WriteLine("Initial data matrix:"); Console.WriteLine(matrix); // Specify a row index. int rowIndex = 3; Console.WriteLine(); Console.WriteLine("Row index: {0}", rowIndex); // Specify all column indexes. var columnIndexes = ":"; Console.WriteLine(); Console.WriteLine("Column indexes: from 0 to {0}", matrix.NumberOfColumns - 1); // Specify the value matrix. var valueData = new Complex[2] { new Complex(40, -40), new Complex(80, -80) }; var value = ComplexMatrix.Dense(1, 2, valueData, StorageOrder.RowMajor); Console.WriteLine(); Console.WriteLine("Value matrix:"); Console.WriteLine(value); // Set the entries having the specified indexes to the value matrix. matrix[rowIndex, columnIndexes] = value; Console.WriteLine(); Console.WriteLine("Updated data matrix:"); Console.WriteLine(matrix); // Entries can also be accessed using a read-only wrapper // of the matrix. ReadOnlyComplexMatrix readOnlyMatrix = matrix.AsReadOnly(); Console.WriteLine(); Console.WriteLine("Updated matrix entries:"); Console.WriteLine(readOnlyMatrix[rowIndex, columnIndexes]); } } } // Executing method Main() produces the following output: // // Initial data matrix: // ( 1, -1) ( 5, -5) // ( 2, -2) ( 6, -6) // ( 3, -3) ( 7, -7) // ( 4, -4) ( 8, -8) // // // // Row index: 3 // // Column indexes: from 0 to 1 // // Value matrix: // ( 40, -40) ( 80, -80) // // // // Updated data matrix: // ( 1, -1) ( 5, -5) // ( 2, -2) ( 6, -6) // ( 3, -3) ( 7, -7) // ( 40, -40) ( 80, -80) // // // // Updated matrix entries: // ( 40, -40) ( 80, -80) //