horzcat
Joins arrays side by side.
Category: Language Fundamentals > Matrices and Arrays
Syntax
C = horzcat(A, B, ...)
Same as [A, B, ...].
Description
The function form of the bracket syntax is useful with cellfun or when the list of inputs is built at run time as a cell array, as in horzcat(c{:}). It also joins text (horzcat('ab', 'cd') is 'abcd') and cell arrays.
If the row counts differ the call fails with a dimension error.
Input arguments
A, B, ...- Arrays with the same number of rows.
Output arguments
C- Array whose columns are those of the inputs in order.
Example
horzcat([1; 2], [3; 4])
horzcat('ab', 'cd')
c = {[1 2], [3], [4 5 6]};
horzcat(c{:})
Output
ans = 2×2
1 3
2 4
ans = 'abcd'
ans = 1×6
1 2 3 4 5 6