Please note that the recommended version of Scilab is 2025.0.0. This page might be outdated.
See the recommended documentation of this function
cat
stacks vectors matrices or arrays into an hypermatrix or hyperarray
Syntax
y = cat(dim, A1, A2, ...,An)
Arguments
- dim
integer>0: index of the dimension along which input arrays must be stacked.
- A1, A2,..An
scalars, vectors, matrices or hypermatrices of the same data type, or cells arrays.
A1,A2,...,An
must be of the same sizes, except in the direction #dim
of stacking :size(A1,i)=size(A2,i)=...=size(An,i)
for alli <> dim
.- y
a vector, matrix, hypermatrix of A1's data type, or an hypercell. For all
i <> dim
,size(y,i)==size(A1,i)
, andsize(y,dim) == sum(size(Ai, dim)))
.
Description
y=cat(dim,A1,A2,...,An)
: y
is the result of the
concatenation of the input arguments A1,A2,...,An
, along the
dimension #dim.
cat(1, A1, A2, A3)
is equivalent to [A1 ; A2 ; A3]
.
cat(2, A1, A2, A3)
is equivalent to [A1 A2 A3]
.
Brackets are faster and must be preferred in both cases.
cat()
is useful mainly for dim > 2
, to build an
hypermatrix or hypercell.
Examples
Example #1: Building a vector along dim #3
cat(3, 4, -1, 3)
--> cat(3, 4, -1, 3) ans = (:,:,1) 4. (:,:,2) -1. (:,:,3) 3.
Example #2: Building a matrix of text of size(1,3,2):
cat(3, ["a" "aa" "aaa"], ["b" "bb" "bbb"])
--> cat(3, ["a" "aa" "aaa"], ["b" "bb" "bbb"]) ans = (:,:,1) !a aa aaa ! (:,:,2) !b bb bbb !
Example #3: Stacking separate R G B layers of a mini RGB image:
R = uint8(grand(2,4,"uin",0,255)) G = uint8(grand(2,4,"uin",0,255)) B = uint8(grand(2,4,"uin",0,255)) cat(3, R, G, B)
--> R = uint8(grand(2,4,"uin",0,255)) R = 142 8 11 234 191 249 252 51 --> G = uint8(grand(2,4,"uin",0,255)) G = 255 246 104 89 152 71 112 17 --> B = uint8(grand(2,4,"uin",0,255)) B = 170 182 39 197 115 108 16 51 --> cat(3, R, G, B) ans = (:,:,1) 142 8 11 234 191 249 252 51 (:,:,2) 255 246 104 89 152 71 112 17 (:,:,3) 170 182 39 197 115 108 16 51
Example #4: Building an hypercell:
--> A1 = {%T "abc" ; (1-%z)^2, %pi} A1 = [1x1 boolean ] [1x1 string ] [1x1 polynomial] [1x1 constant] --> A2 = {%s^2, gda(); %F, list(-5, "hello")} A2 = [1x1 polynomial] [1x1 handle] [1x1 boolean ] [ list ] --> cat(3, A1, A2) ans = (:,:,1) [1x1 boolean ] [1x1 string ] [1x1 polynomial] [1x1 constant] (:,:,2) [1x1 polynomial] [1x1 handle] [1x1 boolean ] [ list ]
See also
- brackets [..] — Concaténation. Récipients d'une affectation. Résultats d'une function
- lstcat — concaténation de listes
- permute — permute les dimensions d'un tableau à N dimensions
- matrix — redimensionne un tableau, à nombre et ordre inchangés des éléments
Report an issue | ||
<< is<forme> | Matrice - façonnage | circshift >> |