Click or drag to resize

DoubleMatrixItem Property (Int32, Int32)

Gets or sets the element of this instance corresponding to the specified row and column indexes.

Namespace:  Novacta.Analytics
Assembly:  Novacta.Analytics (in Novacta.Analytics.dll) Version: 2.0.0
Syntax
public double this[
	int rowIndex,
	int columnIndex
] { get; set; }

Parameters

rowIndex
Type: SystemInt32
The zero-based row index of the element to get or set.
columnIndex
Type: SystemInt32
The zero-based column index of the element to get or set.

Property Value

Type: Double
The element corresponding to the specified row and column indexes.

Implements

IReadOnlyTabularCollectionTValue, TCollectionItemInt32, Int32
ITabularCollectionTValue, TCollectionItemInt32, Int32
Exceptions
ExceptionCondition
ArgumentOutOfRangeExceptionrowIndex is less than zero.
-or-
rowIndex is equal to or greater than NumberOfRows.
-or-
columnIndex is less than zero.
-or-
columnIndex is equal to or greater than NumberOfColumns.
Examples

In the following example, a matrix element is accessed using its row and column indexes.

C#
using System;

namespace Novacta.Analytics.CodeExamples
{
    public class MatrixIndexerExample00  
    {
        public void Main()
        {
            // Create a matrix.
            var data = new double[6] {
                10, 20, 30,
                40, 50, 60
            };
            var matrix = DoubleMatrix.Dense(2, 3, data, StorageOrder.RowMajor);
            Console.WriteLine("Initial data matrix:");
            Console.WriteLine(matrix);

            // Specify a row index.
            int rowIndex = 1;
            Console.WriteLine();
            Console.WriteLine("Row index: {0}", rowIndex);

            // Specify a column index.
            int columnIndex = 2;
            Console.WriteLine();
            Console.WriteLine("Column index: {0}", columnIndex);

            // Set the corresponding entry.
            matrix[rowIndex, columnIndex] = -60.0;

            Console.WriteLine();
            Console.WriteLine("Updated data matrix:");
            Console.WriteLine(matrix);

            // Entries can also be accessed using a read-only wrapper of the matrix.
            ReadOnlyDoubleMatrix readOnlyMatrix = matrix.AsReadOnly();

            Console.WriteLine();
            Console.WriteLine("Updated matrix entry:");
            Console.WriteLine(readOnlyMatrix[rowIndex, columnIndex]);
        }
    }
}

// Executing method Main() produces the following output:
// 
// Initial data matrix:
// 10               20               30               
// 40               50               60               
// 
// 
// 
// Row index: 1
// 
// Column index: 2
// 
// Updated data matrix:
// 10               20               30               
// 40               50               -60              
// 
// 
// 
// Updated matrix entry:
// -60

See Also