Please note that the recommended version of Scilab is 2023.1.0. This page might be outdated.
See the recommended documentation of this function
trim or/and extend (and cast) a matrix or hypermatrix
resMat = resize_matrix(mat, nbRows, nbCols) resMat = resize_matrix(mat, nbRows, nbCols, resType) resMat = resize_matrix(mat, nbRows, nbCols, resType, padding) resMat = resize_matrix(mat, nbRows, nbCols, "" , padding) resMat = resize_matrix(mat, newSizes) resMat = resize_matrix(mat, newSizes, resType) resMat = resize_matrix(mat, newSizes, resType, padding) resMat = resize_matrix(mat, newSizes, "" , padding)
input matrix or hypermatrix. booleans, encoded integers, decimals (real or complexes), polynomials, or text are supported.
new number of rows of the resized matrix. Exceeding rows are trimmed. Missing rows are padded
new number of columns of the resized matrix. Exceeding columns are trimmed. Missing columns are padded
vector specifying the new sizes along each dimension of
If it is shorter than
size(mat), it is padded with ones. Example: if
size(mat)==[ 4 3 3 2]is provided and
newSizes=[6 2]is specified,
newSizes = [6 2 1 1]is considered.
newSizesis longer than
size(mat), new dimensions are added to
matand padded. Example: if
size(mat)==[ 4 3 ]is provided and
newSizes=[6 2 2]is specified, the result will be an hypermatrix with 2 pages, the second one being fully padded.
newSizes = [nbRows, nbCols]may be used for a matrix.
optional scalar of same type as
mat, specifying the content to set in elements created when the size along a dimension is increased. The default padding is done with
0(real or complex decimals, encoded integers, polynomials), or
paddingtypes do not match, scilab tries to convert the
For polynomials, the varname of the padding is forced to the
optional text word specifying the data type into which the resized matrix must be converted. "boolean", "constant", "string", "int8", "uint8", "int16", "uint16", "int32", and "uint32" are supported.
Type conversion is supported neither for Polynomials nor for hypermatrix of text.
resized (and converted) matrix or hypermatrix
Creates a matrix of sizes
[nbRows, nbCols] or
newSizes, or an hypermatrix of sizes
If for a dimension the new size is smaller than the initial one, the matrix is cropped. If the size is increased, the matrix/hypermatrix is padded.
The number of dimensions can be increased. Respectively, Scilab automatically squeezes highest dimensions with size kept or set to 1 (singletons).
The type of the result may be changed by specifying the
resType argument, with restrictions given above.
// Embedded examples, including with polynomials: resize_matrix // Numerical matrix: M = grand(4, 3, "uin", -9, 9) resize_matrix(M, 3, 4) resize_matrix(M, [3 4 2]) resize_matrix(M, [3 4 2], "", %i) resize_matrix(M, [3 4 2], "string", %i) // Matrix of text: myMatString = ["Scilab", "the"; "Open Source", "Scientific"; "Software", "Package"] resize_matrix( myMatString, 5, 3 ) // Equivalent syntax for new sizes: resize_matrix( myMatString, [5 3], "", "$" ) // With custom padding // Crops, pads and casts an hypermatrix: h = rand(2, 3, 2)*200 resize_matrix(h, [3 2 3], "int8") resize_matrix(h, [3 2 3], "int8", -1) // Custom padding r = resize_matrix(h, [3 2 ] , "" , -1) // Custom padding without type conversion size(r) // The last dimension has been squeezed // With Polynomials: x = poly(0, "x"); P = (1-x)^grand(4, 2, "uin", 0, 3) resize_matrix(P, 3, 3) resize_matrix(P, [3 3 2]) resize_matrix(P, [3 3 2], "", %z) // => The padding's unknown is forced to the P's one // => Polynomials can't be converted
|5.5.0||Polynomials and Hypermatrices are now accepted. Custom padding can now be provided. New sizes can be specified in a vector. resize_matrix with no parameters displays examples (demo).|
|Report an issue|
|<< repmat||Matrix manipulation||squeeze >>|