I am trying to take the matrix
base =[1 2; 3 4]
and replicate the elements to give
expn = [ 1 1 2 2; 1 1 2 2; 3 3 4 4; 3 3 4 4]
without using for loops. I would like to use repmat but not sure how to do that elementwise.

댓글 수: 1

Howard Wilton
Howard Wilton 2022년 11월 22일
Got it!
N = 2; base = [1 2; 3 4]
expn = kron(base,ones(N))

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

 채택된 답변

David Hill
David Hill 2022년 11월 22일
base =[1 2; 3 4];
repelem(base,2,2)
ans = 4×4
1 1 2 2 1 1 2 2 3 3 4 4 3 3 4 4

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

제품

릴리스

R2020b

질문:

2022년 11월 22일

댓글:

2022년 11월 22일

Community Treasure Hunt

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

Start Hunting!

Translated by