matrix padding with zero
古いコメントを表示
I have a 3x3 matrix and a 2x3 matrix. I need to pad zeros in the 2x3 matrix only at the bottom row such that it becomes 3x3.
If i have another matrix let's say 5x4 and second one 5x2, i need to pad the last 2 columns of the 5x2 matrix such that it has same rows and columns as 5x4.
a = [1,2,3; 3,2,1; 1,2,3];
b = [1,2,3; 3,2,1];
d = padarray(b,[1,0],0)
This code is padding a row above and a row below the matrix but i just want it below the 2x3 matrix.
4 件のコメント
Anvinder
2016 年 3 月 30 日
Image Analyst
2016 年 3 月 30 日
What is the second and what is the first? Please give examples with actual numbers of the two arrays and the final output array.
Anvinder
2016 年 4 月 1 日
Image Analyst
2016 年 4 月 1 日
Yep, my answer below will do it. Simply assign the lower right element to zero, even if that element does not exist yet, and it will pad everything up to there with zeros.
採用された回答
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Creating and Concatenating Matrices についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!