フィルターのクリア

How do I double the size of a given matrix?

3 ビュー (過去 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 Center および File ExchangeShifting and Sorting Matrices についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by