How do I double the size of a given matrix?

조회 수: 4 (최근 30일)
Steven Gangano
Steven Gangano 2022년 4월 8일
댓글: Steven Gangano 2022년 4월 8일
A = [ 1 2
3 4
]
I want to double the size of matrix A by adding a duplicate of row 1 underneath it.
And also adding a duplicate of row 2 underneath it.
This is a simple example, but I will be doing this for a much larger matrix of 300x500. What is the best way to tackle this?
B = [ 1 2
1 2
3 4
3 4
]

답변 (1개)

KSSV
KSSV 2022년 4월 8일
편집: KSSV 2022년 4월 8일
A = [ 1 2
3 4] ;
iwant = repelem(A,2,1)
iwant = 4×2
1 2 1 2 3 4 3 4
  댓글 수: 3
KSSV
KSSV 2022년 4월 8일
[m, n] = size(A) ; B = zeros(2*m, n) ; B(1:m,:) = A(1,:) ; B(m+1:end, :) = A(2, :) ;
Steven Gangano
Steven Gangano 2022년 4월 8일
Thank you!

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

카테고리

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