필터 지우기
필터 지우기

concatenation in a loop

조회 수: 45 (최근 30일)
Aniket Kumar
Aniket Kumar 2019년 6월 8일
답변: Prasanth Sikakollu 2019년 6월 8일
Can we concatenate two matrices in a loop? (size of one matrix will increase after every iteration)
for me its showing this error
"Error using cat
Dimensions of matrices being concatenated are not consistent."
  댓글 수: 1
madhan ravi
madhan ravi 2019년 6월 8일
Show the code.

댓글을 달려면 로그인하십시오.

채택된 답변

Prasanth Sikakollu
Prasanth Sikakollu 2019년 6월 8일
For row wise concatenation:
Here, matrix 'c' is being concatenated to matrix 'a' row wise, number of columns being constant in this case.
a = [];
c = [1 2;3 4];
for i = 1:5
c = [1*i 2*i;3*i 4*i];
a = [a;c]; % For row wise concatenation
end
For column wise concatenation:
Here matrix 'c' is being concatenated to matrix 'a' column wise, number of rows being constant in this case.
a = [];
c = [1 2;3 4];
for i = 1:5
c = [1*i 2*i;3*i 4*i];
a = [a c]; % For column wise concatenation
end
Hope this helps

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by