필터 지우기
필터 지우기

Concatenate a variable number of matrices

조회 수: 5 (최근 30일)
Yasmin Tamimi
Yasmin Tamimi 2017년 10월 23일
편집: Stephen23 2017년 10월 23일
Hi All,
How can I concatenate a variable number of matrices that is decided by the user's input?
Thanks..
  댓글 수: 1
Stephen23
Stephen23 2017년 10월 23일
편집: Stephen23 2017년 10월 23일
This is simple. Ensure that you store all of the matrices in one cell array C, then you can simply do this:
cat(3,C{:})
You can change the dimension to suit your needs. Also you can easily select how many you want to concatenate, by using simple and efficient indexing 1:N:
cat(3,C{1:N})
Note that accessing lots of separate variables inside a loop is very slow, complex and buggy:

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

답변 (1개)

KL
KL 2017년 10월 23일
편집: KL 2017년 10월 23일
I suppose your matrices have (in fact, they should be) consistent dimensions, so you could as well store them in ND array.
dummy = rand(3,3,5);
user_choice = 3; %concatenate first 3 matrices
res = reshape(dummy(:,:,1:user_choice),size(dummy,1),size(dummy,2)*user_choice)
Is this what you want?

카테고리

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