Scilab Website | Contribute with GitLab | Mailing list archives | ATOMS toolboxes
Scilab Online Help
2025.0.0 - Français


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 compatible data types, 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 all i <> dim.

y

a vector, matrix, hypermatrix, or ND-array of cells or of structures. For all i <> dim, size(y,i)==size(A1,i), and size(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.

When input arrays have not all the same data type, automatical conversion rules similar to the [,] and [;] ones are applied, as described in the [brackets] page.

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}
A2 = {%s^2, gda(); %F, list(-5, "hello")}
cat(3, A1, A2)
--> 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

History

VersionDescription
2023.1 Arrays of compatible types accepted, according to [,] and [;] transtyping rules.
Report an issue
<< is<forme> Matrice - façonnage circshift >>

Copyright (c) 2022-2024 (Dassault Systèmes)
Copyright (c) 2017-2022 (ESI Group)
Copyright (c) 2011-2017 (Scilab Enterprises)
Copyright (c) 1989-2012 (INRIA)
Copyright (c) 1989-2007 (ENPC)
with contributors
Last updated:
Thu Oct 24 11:15:58 CEST 2024