How can I concatenate an arbitrary number (#) of nxm matrices to make a 3D (# by n by m) matrix?

조회 수: 1 (최근 30일)
Suppose I had a matrix A=[1:3;4:6;7:9], and then have B=cat(3,A,A,A,A) which creates a 3rd dimension and concatenates matrix A with itself 4 times. What I would like is to do this for an arbitrary length in this new dimension without using for loops which are drastically slower than typing out A,A,A.. 100 times. Thanks in advance!

채택된 답변

Azzi Abdelmalek
Azzi Abdelmalek 2014년 7월 25일
n=4
A=[1:3;4:6;7:9]
bsxfun(@times,A,ones(1,1,n))
  댓글 수: 1
Callum
Callum 2014년 7월 25일
Ah brilliant haha. I thought @times would multiply the matrices together since @plus adds them. Cheers though!

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

추가 답변 (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