Adding elements to an array
조회 수: 135 (최근 30일)
이전 댓글 표시
Ok, so how do you place elements of one array into another array, so that they are included in either the beginning of the array or the end of the array?
댓글 수: 0
채택된 답변
topdawgnate
2011년 9월 21일
편집: MathWorks Support Team
2018년 11월 8일
There are many ways to join elements of two arrays. For example, let’s say you have two 2-by-2 matrices A and B:
A = [1 2; 3 4];
B = [5 6; 7 8];
Then the following commands concatenate B to the end of A horizontally:
H1 = [A B]
H2 = horzcat(A,B)
H3 = cat(2,A,B)
The first argument in the cat function (2) tells it to add B as additional columns of A.
These commands concatenate B to the end of A vertically:
V1 = [A; B]
V2 = vertcat(A,B)
V3 = cat(1,A,B)
The 1 tells cat to add B as additional rows of A.
For additional concatenation examples, see:
추가 답변 (1개)
YU-CHENG HUANG
2017년 9월 29일
just using c = [a , b]
ex: a = [1 2 3] b = [4 5 6] c = [a,b]
--> c = [1 2 3 4 5 6]
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!