Package org.djunits.vecmat.table
Class QuantityTable<Q extends Quantity<Q,U>,U extends UnitInterface<U,Q>>
java.lang.Object
org.djunits.vecmat.def.VectorMatrix<Q,U,QuantityTable<Q,U>,QuantityTable<SIQuantity,SIUnit>,QuantityTable<?,?>>
org.djunits.vecmat.table.QuantityTable<Q,U>
- Type Parameters:
Q- the quantity typeU- the unit type
- All Implemented Interfaces:
Serializable,Additive<QuantityTable<Q,,U>> Scalable<QuantityTable<Q,,U>> Value<U,,QuantityTable<Q, U>> Hadamard<QuantityTable<?,?>, QuantityTable<SIQuantity, SIUnit>>
public class QuantityTable<Q extends Quantity<Q,U>,U extends UnitInterface<U,Q>>
extends VectorMatrix<Q,U,QuantityTable<Q,U>,QuantityTable<SIQuantity,SIUnit>,QuantityTable<?,?>>
QuantityTable is a two-dimensonal table with quantities. The QuantityTable allows for Hadamard (element-wise) operations, but
not for vector/matrix operations. A QuantityTable can be transformed to a MatrixNxM or vice versa.
Copyright (c) 2025-2026 Delft University of Technology, Jaffalaan 5, 2628 BX Delft, the Netherlands. All rights reserved. See for project information https://djunits.org. The DJUNITS project is distributed under a three-clause BSD-style license.
- Author:
- Alexander Verbraeck
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionQuantityTable(DataGridSi<?> dataSi, U displayUnit) Create a new NxM QuantityTable with a unit, based on a DataGrid storage object. -
Method Summary
Modifier and TypeMethodDescription<TQ extends Quantity<TQ,TU>, TU extends UnitInterface<TU, TQ>>
QuantityTable<TQ,TU> as(TU targetUnit) Return the QuantityTable 'as' a QuantityTable with a known quantity, using a unit to express the result in.Convert this QuantityTable to aMatrix1x1.Convert this QuantityTable to aMatrix2x2.Convert this QuantityTable to aMatrix3x3.Convert this QuantityTable to aMatrixNxN.Convert this QuantityTable to a 1-element column vector.Convert this QuantityTable to a 2-element column vector.Convert this QuantityTable to a 2-element row vector.Convert this QuantityTable to a 3-element column vector.Convert this QuantityTable to a 3-element row vector.Convert this QuantityTable to an N-element column vector.Convert this QuantityTable to an N-element row vector.intcols()Return the number of columns.booleandouble[]getColumnSi(int col) Return an array with SI-values for the given column (0-based) from the vector or matrix.getColumnVector(int col) Return a quantity column (0-based) from the vector or matrix.DataGridSi<?>Return the internal datagrid object, so we can retrieve data from it.double[]getRowSi(int row) Return an array with SI-values for the given row (0-based) from the vector or matrix.getRowVector(int row) Return a quantity row (0-based) from the vector or matrix.inthashCode()instantiateSi(double[] siNew) Return a new vector or matrix with the given SI or BASE values.instantiateSi(double[] siNew, SIUnit siUnit) Return a new vector or matrix in SI-units with the given SI or BASE values.mgetColumnVector(int mCol) Return a quantity column (1-based) from the vector or matrix.mgetRowVector(int mRow) Return a quantity row (1-based) from the vector or matrix.static <Q extends Quantity<Q,U>, U extends UnitInterface<U, Q>>
QuantityTable<Q,U> of(double[][] valueGridInUnit, U displayUnit) Create a new NxM QuantityTable with a unit, based on a 2-dimensional double grid.static <Q extends Quantity<Q,U>, U extends UnitInterface<U, Q>>
QuantityTable<Q,U> of(double[] valueArrayInUnit, int rows, int cols, U displayUnit) Create a new NxM QuantityTable with a unit, based on a 1-dimensional double array.static <Q extends Quantity<Q,U>, U extends UnitInterface<U, Q>>
QuantityTable<Q,U> of(Q[][] quantityGrid, U displayUnit) Create a new NxM QuantityTable with a unit, based on a 2-dimensional quantity grid.introws()Return the number of rows.double[]si()Return a row-major array of SI-values for this matrix or vector.doublesi(int row, int col) Return the si-value at position (row, col), where both row and col are 0-based values.Methods inherited from class org.djunits.vecmat.def.VectorMatrix
abs, add, add, asMatrixNxM, asQuantityTable, checkCol, checkRow, divideElements, divideElements, get, getColumnScalars, getDisplayUnit, getRowScalars, getScalarGrid, invertElements, isRelative, max, mcheckCol, mcheckRow, mean, median, mget, mgetColumnScalars, mgetColumnSi, mgetRowScalars, mgetRowSi, min, mode, msi, multiplyElements, multiplyElements, multiplyElements, negate, scaleBy, setDisplayUnit, subtract, subtract, sum, toString, toStringMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface org.djunits.vecmat.operations.Hadamard
divideElementsMethods inherited from interface org.djunits.value.Value
isAbsolute, setDisplayUnit
-
Constructor Details
-
QuantityTable
Create a new NxM QuantityTable with a unit, based on a DataGrid storage object. This constructor assumes dataSi stores SI values. Note: NO safe copy is made.- Parameters:
dataSi- the data of the matrix, in SI unit.displayUnit- the display unit to use
-
-
Method Details
-
of
public static <Q extends Quantity<Q,U>, QuantityTable<Q,U extends UnitInterface<U, Q>> U> of(double[] valueArrayInUnit, int rows, int cols, U displayUnit) Create a new NxM QuantityTable with a unit, based on a 1-dimensional double array.- Type Parameters:
Q- the quantity typeU- the unit type- Parameters:
valueArrayInUnit- the matrix values {a11, a12, ..., a1M, aN2, ..., aNM} expressed in the display unitdisplayUnit- the display unit to userows- the number of rows in the valueArraycols- the number of columns in the valueArray- Returns:
- a new NxM QuantityTable with a unit
- Throws:
IllegalArgumentException- when rows or cols is not positive, or when the number of entries in valueArray is not equal to rows*cols
-
of
public static <Q extends Quantity<Q,U>, QuantityTable<Q,U extends UnitInterface<U, Q>> U> of(double[][] valueGridInUnit, U displayUnit) Create a new NxM QuantityTable with a unit, based on a 2-dimensional double grid.- Type Parameters:
Q- the quantity typeU- the unit type- Parameters:
valueGridInUnit- the matrix values {{a11, a12, a1M}, ..., {aN1, aN2, aNM}} expressed in the display unitdisplayUnit- the display unit to use- Returns:
- a new NxM QuantityTable with a unit
- Throws:
IllegalArgumentException- when valueGrid has 0 rows, or when the number of columns for one of the rows is not equal to the number of columns in another row
-
of
public static <Q extends Quantity<Q,U>, QuantityTable<Q,U extends UnitInterface<U, Q>> U> of(Q[][] quantityGrid, U displayUnit) Create a new NxM QuantityTable with a unit, based on a 2-dimensional quantity grid.- Type Parameters:
Q- the quantity typeU- the unit type- Parameters:
quantityGrid- the matrix values {{a11, a12, ..., a1M}, {aN2, ..., aNM}}, each with their own unitdisplayUnit- the display unit to use for the resulting matrix- Returns:
- a new NxM QuantityTable with a unit
- Throws:
IllegalArgumentException- when rows or cols is not positive, or when the number of entries in quantityGrid is not equal to rows*cols
-
instantiateSi
Description copied from class:VectorMatrixReturn a new vector or matrix with the given SI or BASE values.- Specified by:
instantiateSiin classVectorMatrix<Q extends Quantity<Q,U>, U extends UnitInterface<U, Q>, QuantityTable<Q extends Quantity<Q, U>, U extends UnitInterface<U, Q>>, QuantityTable<SIQuantity, SIUnit>, QuantityTable<?, ?>> - Parameters:
siNew- the values for the new vector or matrix in row-major format- Returns:
- a new matrix with the provided SI or BASE values
-
instantiateSi
Description copied from class:VectorMatrixReturn a new vector or matrix in SI-units with the given SI or BASE values.- Specified by:
instantiateSiin classVectorMatrix<Q extends Quantity<Q,U>, U extends UnitInterface<U, Q>, QuantityTable<Q extends Quantity<Q, U>, U extends UnitInterface<U, Q>>, QuantityTable<SIQuantity, SIUnit>, QuantityTable<?, ?>> - Parameters:
siNew- the values for the new vector or matrix in row-major formatsiUnit- the new unit for the new vector or matrix- Returns:
- a new matrix with the provided SI or BASE values
-
getDataGrid
Return the internal datagrid object, so we can retrieve data from it.- Returns:
- the internal datagrid object
-
si
public double[] si()Description copied from class:VectorMatrixReturn a row-major array of SI-values for this matrix or vector. Note that this is NOT a safe copy.- Specified by:
siin classVectorMatrix<Q extends Quantity<Q,U>, U extends UnitInterface<U, Q>, QuantityTable<Q extends Quantity<Q, U>, U extends UnitInterface<U, Q>>, QuantityTable<SIQuantity, SIUnit>, QuantityTable<?, ?>> - Returns:
- the row-major array of SI-values
-
si
Description copied from class:VectorMatrixReturn the si-value at position (row, col), where both row and col are 0-based values.- Specified by:
siin classVectorMatrix<Q extends Quantity<Q,U>, U extends UnitInterface<U, Q>, QuantityTable<Q extends Quantity<Q, U>, U extends UnitInterface<U, Q>>, QuantityTable<SIQuantity, SIUnit>, QuantityTable<?, ?>> - Parameters:
row- the row (0-based)col- the column (0-based)- Returns:
- the si-value at position (row, col)
- Throws:
IndexOutOfBoundsException- when row or col < 0 or larger than number of rows/columns - 1.
-
getRowVector
Description copied from class:VectorMatrixReturn a quantity row (0-based) from the vector or matrix. Note that the specific vector to return can be tightened by the implementing class.- Specified by:
getRowVectorin classVectorMatrix<Q extends Quantity<Q,U>, U extends UnitInterface<U, Q>, QuantityTable<Q extends Quantity<Q, U>, U extends UnitInterface<U, Q>>, QuantityTable<SIQuantity, SIUnit>, QuantityTable<?, ?>> - Parameters:
row- the row number to retrieve (0-based)- Returns:
- a row vector with the data at the given row
-
mgetRowVector
Description copied from class:VectorMatrixReturn a quantity row (1-based) from the vector or matrix. Note that the specific vector to return can be tightened by the implementing class.- Specified by:
mgetRowVectorin classVectorMatrix<Q extends Quantity<Q,U>, U extends UnitInterface<U, Q>, QuantityTable<Q extends Quantity<Q, U>, U extends UnitInterface<U, Q>>, QuantityTable<SIQuantity, SIUnit>, QuantityTable<?, ?>> - Parameters:
mRow- the row number to retrieve (1-based)- Returns:
- a row vector with the data at the given row
-
getColumnVector
Description copied from class:VectorMatrixReturn a quantity column (0-based) from the vector or matrix. Note that the specific vector to return can be tightened by the implementing class.- Specified by:
getColumnVectorin classVectorMatrix<Q extends Quantity<Q,U>, U extends UnitInterface<U, Q>, QuantityTable<Q extends Quantity<Q, U>, U extends UnitInterface<U, Q>>, QuantityTable<SIQuantity, SIUnit>, QuantityTable<?, ?>> - Parameters:
col- the column number to retrieve (0-based)- Returns:
- a column vector with the data at the given column
-
mgetColumnVector
Description copied from class:VectorMatrixReturn a quantity column (1-based) from the vector or matrix. Note that the specific vector to return can be tightened by the implementing class.- Specified by:
mgetColumnVectorin classVectorMatrix<Q extends Quantity<Q,U>, U extends UnitInterface<U, Q>, QuantityTable<Q extends Quantity<Q, U>, U extends UnitInterface<U, Q>>, QuantityTable<SIQuantity, SIUnit>, QuantityTable<?, ?>> - Parameters:
mCol- the column number to retrieve (1-based)- Returns:
- a column vector with the data at the given column
-
getRowSi
public double[] getRowSi(int row) Description copied from class:VectorMatrixReturn an array with SI-values for the given row (0-based) from the vector or matrix.- Specified by:
getRowSiin classVectorMatrix<Q extends Quantity<Q,U>, U extends UnitInterface<U, Q>, QuantityTable<Q extends Quantity<Q, U>, U extends UnitInterface<U, Q>>, QuantityTable<SIQuantity, SIUnit>, QuantityTable<?, ?>> - Parameters:
row- the row number to retrieve (0-based)- Returns:
- an array with SI-values with the data at the given row
-
getColumnSi
public double[] getColumnSi(int col) Description copied from class:VectorMatrixReturn an array with SI-values for the given column (0-based) from the vector or matrix.- Specified by:
getColumnSiin classVectorMatrix<Q extends Quantity<Q,U>, U extends UnitInterface<U, Q>, QuantityTable<Q extends Quantity<Q, U>, U extends UnitInterface<U, Q>>, QuantityTable<SIQuantity, SIUnit>, QuantityTable<?, ?>> - Parameters:
col- the column number to retrieve (0-based)- Returns:
- an array with SI-values with the data at the given column
-
rows
public int rows()Description copied from class:VectorMatrixReturn the number of rows.- Specified by:
rowsin classVectorMatrix<Q extends Quantity<Q,U>, U extends UnitInterface<U, Q>, QuantityTable<Q extends Quantity<Q, U>, U extends UnitInterface<U, Q>>, QuantityTable<SIQuantity, SIUnit>, QuantityTable<?, ?>> - Returns:
- the number of rows
-
cols
public int cols()Description copied from class:VectorMatrixReturn the number of columns.- Specified by:
colsin classVectorMatrix<Q extends Quantity<Q,U>, U extends UnitInterface<U, Q>, QuantityTable<Q extends Quantity<Q, U>, U extends UnitInterface<U, Q>>, QuantityTable<SIQuantity, SIUnit>, QuantityTable<?, ?>> - Returns:
- the number of columns
-
hashCode
public int hashCode() -
equals
-
as
public <TQ extends Quantity<TQ,TU>, QuantityTable<TQ,TU extends UnitInterface<TU, TQ>> TU> as(TU targetUnit) throws IllegalArgumentException Return the QuantityTable 'as' a QuantityTable with a known quantity, using a unit to express the result in. Throw a Runtime exception when the SI units of this vector and the target vector do not match.- Type Parameters:
TQ- target quantity typeTU- target unit type- Parameters:
targetUnit- the unit to convert the quantity table to- Returns:
- a quantity table typed in the target quantity table class
- Throws:
IllegalArgumentException- when the units do not match
-
asMatrix1x1
Convert this QuantityTable to aMatrix1x1. The shape must be 1 x 1.- Returns:
- a
Matrix1x1with identical SI data and display unit - Throws:
IllegalStateException- if this matrix is not 1 x 1
-
asMatrix2x2
Convert this QuantityTable to aMatrix2x2. The shape must be 2 x 2.- Returns:
- a
Matrix2x2with identical SI data and display unit - Throws:
IllegalStateException- if this matrix is not 2 x 2
-
asMatrix3x3
Convert this QuantityTable to aMatrix3x3. The shape must be 3 x 3.- Returns:
- a
Matrix3x3with identical SI data and display unit - Throws:
IllegalStateException- if this matrix is not 3 x 3
-
asMatrixNxN
Convert this QuantityTable to aMatrixNxN. The shape must be square.- Returns:
- a
MatrixNxNwith identical SI data and display unit - Throws:
IllegalStateException- if this matrix is not square
-
asVector1
Convert this QuantityTable to a 1-element column vector. Shape must be 1 x 1.- Returns:
- a
Vector1with identical SI data and display unit - Throws:
IllegalStateException- if shape is not 1 x 1
-
asVector2Col
Convert this QuantityTable to a 2-element column vector. Shape must be 2 x 1.- Returns:
- a
Vector2.Colwith identical SI data and display unit - Throws:
IllegalStateException- if shape is not 2 x 1
-
asVector3Col
Convert this QuantityTable to a 3-element column vector. Shape must be 3 x 1.- Returns:
- a
Vector3.Colwith identical SI data and display unit - Throws:
IllegalStateException- if shape is not 3 x 1
-
asVectorNCol
Convert this QuantityTable to an N-element column vector. Shape must be N x 1.- Returns:
- a
VectorN.Colwith identical SI data and display unit - Throws:
IllegalStateException- ifcols() != 1
-
asVector2Row
Convert this QuantityTable to a 2-element row vector. Shape must be 1 x 2.- Returns:
- a
Vector2.Rowwith identical SI data and display unit - Throws:
IllegalStateException- if shape is not 1 x 2
-
asVector3Row
Convert this QuantityTable to a 3-element row vector. Shape must be 1 x 3.- Returns:
- a
Vector3.Rowwith identical SI data and display unit - Throws:
IllegalStateException- if shape is not 1 x 3
-
asVectorNRow
Convert this QuantityTable to an N-element row vector. Shape must be 1 x N.- Returns:
- a
VectorN.Rowwith identical SI data and display unit - Throws:
IllegalStateException- ifrows() != 1
-