フィルターのクリア

Fill a matrix with another buy keep the original size

3 ビュー (過去 30 日間)
Matt
Matt 2023 年 4 月 21 日
コメント済み: Matt 2023 年 4 月 21 日
Hi,
I have a 5x5 matrix (for example) filled with zeroes and I just want to fill that matrix from the top with another one which has fewer rows, say 3x5. What is the most elegant way of doing it?
Thanks!

採用された回答

Stephen23
Stephen23 2023 年 4 月 21 日
編集済み: Stephen23 2023 年 4 月 21 日
A = zeros(5,5);
B = rand(3,5);
A(1:size(B,1),:) = B
A = 5×5
0.6104 0.7423 0.9155 0.5919 0.5947 0.0101 0.6127 0.8947 0.6021 0.8645 0.3824 0.7586 0.2458 0.6549 0.9956 0 0 0 0 0 0 0 0 0 0
  1 件のコメント
Matt
Matt 2023 年 4 月 21 日
Thank you! That was as simple as this. I'm a bit rusty!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMultidimensional Arrays についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by