Creating a N-Dimentional matrix from a 2 Dimentional matrix

조회 수: 2 (최근 30일)
Jalali
Jalali 2012년 7월 11일
Let's assume I have a as [1 2;3 4]. I need to create b to be 2-by-2-by-100 as follows: b(:,:,1)=[1 2;3 4] . . b(:,:,100)=[1 2;3 4]
I know that function 'cat' works but it's required to repeat the [1 2;3 4] hundred times which is not applicable. Which function should I use here?
Thanks,

채택된 답변

Honglei Chen
Honglei Chen 2012년 7월 11일
a = [1 2 ;3 4]
b = reshape(repmat(a(:),1,100),[size(a) 100]);
  댓글 수: 1
Jalali
Jalali 2012년 7월 11일
Thanks!
How about this case:
I need to create b as 100-by-10-by16 based on a=[1:16]
The following code works, but do you have any simpler idea?
q=repmat(a,[100 1]);
w=reshape(repmat(q(:),1,10),[ size(q) 10]);
b=permute(w,[1 3 2]);

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

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