Padding an array with some size, and the location
古いコメントを表示
Say that we have an array, and I wanted to resize that array while keeping its content. Something I thought of is "padding". When I tried that, I noticed that the original content had different locations in the new array. How can I pad they array, while keeping the original array content in their same location?
Thanks.
採用された回答
その他の回答 (1 件)
Image Analyst
2015 年 2 月 7 日
What did you try? Did you try padarray() in the Image Processing Toolbox?
m = magic(3);
mPadded = padarray(m, [4, 3])
2 件のコメント
med-sweng
2015 年 2 月 7 日
Image Analyst
2015 年 2 月 7 日
OK, glad it worked for you. It took your array and padded around it with zeros just like it was designed to do.
If you want the matrix not to be padded on all sides, but to keep it in the upper left, you can just assign the last element. For example:
b=magic(3);
b(8,6) = 0
b =
8 1 6 0 0 0
3 5 7 0 0 0
4 9 2 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
カテゴリ
ヘルプ センター および File Exchange で Standard File Formats についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!