Replicate matrix elements without for loop

2 ビュー (過去 30 日間)
Howard Wilton
Howard Wilton 2022 年 11 月 22 日
コメント済み: Howard Wilton 2022 年 11 月 22 日
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 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by