i need to pad my matrix only from the ends like this picture

1 view (last 30 days)

Answers (1)

DGM
DGM on 19 Nov 2022
Edited: DGM on 19 Nov 2022
You should be able to use padarray() to pad with constant values.
A = magic(5)
A = 5×5
17 24 1 8 15 23 5 7 14 16 4 6 13 20 22 10 12 19 21 3 11 18 25 2 9
Apadded = padarray(A,[3 3],0,'post')
Apadded = 8×8
17 24 1 8 15 0 0 0 23 5 7 14 16 0 0 0 4 6 13 20 22 0 0 0 10 12 19 21 3 0 0 0 11 18 25 2 9 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
In this example, [3 3] specifies the pad width in each dimension. The pad value is 0, and 'post' specifies that only the trailing edge gets padded in either dimension.

Categories

Find more on Creating and Concatenating Matrices in Help Center and File Exchange

Tags

Products


Release

R2022b

Community Treasure Hunt

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

Start Hunting!