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

1 vue (au cours des 30 derniers jours)
Afnan
Afnan le 19 Nov 2022
Commenté : Bruno Luong le 19 Nov 2022

Réponses (1)

DGM
DGM le 19 Nov 2022
Modifié(e) : DGM le 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.

Catégories

En savoir plus sur Creating and Concatenating Matrices dans Help Center et File Exchange

Tags

Produits


Version

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by