Create a multidimensional array and fill it with n Matrix of the same type

조회 수: 9 (최근 30일)
Lant3rn
Lant3rn 2021년 8월 31일
답변: Pratyay Pande 2021년 9월 3일
Hello Guys,
lets say I have Matrix A = [1 2 3; 4 5 6; 7 8 9] and I want to create a multidimensional Array of size n. Now each page of the multi array should contain the Matrix A. Can somebody give me a hint without using a loop. Would be glad the get some help.
  댓글 수: 1
Lant3rn
Lant3rn 2021년 8월 31일
I got the answer by myself :-): A = repmat(A,[1 1 n]) will do the job. If anyone has another Idea still interested in reading it :-)

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

답변 (1개)

Pratyay Pande
Pratyay Pande 2021년 9월 3일
The approach that @Lant3rn mentioned is correct and also one that is recommended.
Another approach to do the same without using repmat is:
A = A(:,:,ones(1,n));

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by