function getcol
getcol(
x: matrix,
n: number,
): array

Get a column of a matrix.

Retrieves a specific column from a 2D matrix. If the input is not a matrix or if the column index is invalid, an error is thrown.

Examples

Get the first column

import { assertEquals, assertThrows } from "jsr:@std/assert";

assertEquals(getcol([[5, 6, 5], [7, 8, -1]], 0), [5, 7]);

Get the third column

import { assertEquals, assertThrows } from "jsr:@std/assert";

assertEquals(getcol([[5, 6, 5], [7, 8, -1]], 2), [5, -1]);

Invalid column index (out of bounds)

import { assertEquals, assertThrows } from "jsr:@std/assert";

assertThrows(() => { getcol([[5, 6, 5], [7, 8, -1]], 3); }, Error, 'Column index must be an integer between 0 and N - 1 columns');

Parameters

The input matrix (2D array) from which to retrieve the column.

n: number

The column index to retrieve (0-based index).

Return Type

An array representing the specified column of the matrix.

Throws

Throws an error if the input is not a matrix or if the column index is out of bounds.