hvcat
hvcat(rows::Tuple{Vararg{Int}}, values...)
Horizontal and vertical concatenation in one call. This function is called for block matrix syntax. The first argument specifies the number of arguments to concatenate in each block row.
julia> a, b, c, d, e, f = 1, 2, 3, 4, 5, 6
(1,2,3,4,5,6)
julia> [a b c; d e f]
2x3 Array{Int64,2}:
1 2 3
4 5 6
julia> hvcat((3,3), a,b,c,d,e,f)
2x3 Array{Int64,2}:
1 2 3
4 5 6
julia> [a b;c d; e f]
3x2 Array{Int64,2}:
1 2
3 4
5 6
julia> hvcat((2,2,2), a,b,c,d,e,f)
3x2 Array{Int64,2}:
1 2
3 4
5 6
If the first argument is a single integer n
, then all block rows are assumed to have n
block columns.
Examples
julia> foo = Array(Int8,2,2)
2x2 Array{Int8,2}:
-4 -1
-1 -1
julia> bar = Array(Int8,2,2)
2x2 Array{Int8,2}:
-8 124
-117 8
julia> baz = Array(Int8,2,4)
2x4 Array{Int8,2}:
0 0 0 0
0 0 0 0
julia> hvcat((2,1), foo, bar, baz) # equivalent to [foo bar; baz]
4x4 Array{Int8,2}:
-4 -1 -8 124
-1 -1 -117 8
0 0 0 0
0 0 0 0
-
Horizontal and vertical concatenation of integers:
julia> a, b, c, d, e, f = 1, 2, 3, 4, 5, 6 julia> hvcat((3,3), a, b, c, d, e, f) 2×3 Array{Int64,2}: 1 2 3 4 5 6
This example demonstrates the horizontal and vertical concatenation of integers using the
hvcat
function. The first argument(3,3)
specifies that there will be 3 arguments to concatenate in each block row. -
Horizontal and vertical concatenation of arrays:
julia> arr1 = [1, 2, 3] julia> arr2 = [4, 5, 6] julia> hvcat((2,2), arr1, arr2) 3×2 Array{Int64,2}: 1 2 3 4 5 6
In this example, two arrays
arr1
andarr2
are horizontally and vertically concatenated usinghvcat
. -
Specifying a single integer for all block rows:
julia> hvcat(3, a, b, c, d, e, f) 2×3 Array{Int64,2}: 1 2 3 4 5 6
When the first argument is a single integer
n
, it indicates that all block rows haven
block columns. This example shows the same result as the first example, where(3,3)
was explicitly specified. - Concatenation with different block row sizes:
julia> hvcat((2,2,2), a, b, c, d, e, f) 3×2 Array{Int64,2}: 1 2 3 4 5 6
Here, the
hvcat
function is used to concatenate integers with different block row sizes. The first argument(2,2,2)
specifies that each block row will have 2 block columns.
Note: In the provided examples, the variables a
, b
, c
, d
, e
, and f
are assumed to be defined with integer values.
See Also
User Contributed Notes
Add a Note
The format of note supported is markdown, use triple backtick to start and end a code block.