Effacer les filtres
Effacer les filtres

Putting 1 around the matrix

2 vues (au cours des 30 derniers jours)
Offroad Jeep
Offroad Jeep le 23 Sep 2016
Commenté : Offroad Jeep le 23 Sep 2016
Hi I have a 3X3 matrix and want to put 1 around the matrix as it will become 4X4 matrix.....
  3 commentaires
Offroad Jeep
Offroad Jeep le 23 Sep 2016
ya sorry its 5X5
Offroad Jeep
Offroad Jeep le 23 Sep 2016
yes I need 3X3 matrix Converted to 5X5 by putting 1 all around

Connectez-vous pour commenter.

Réponse acceptée

Andrei Bobrov
Andrei Bobrov le 23 Sep 2016
Let A - your matrix [3 x 3]:
A = magic(3);
out = ones(2 + size(A));
out(2:end-1,2:end-1) = A;
  1 commentaire
Offroad Jeep
Offroad Jeep le 23 Sep 2016
Thanks ..... worked

Connectez-vous pour commenter.

Plus de réponses (1)

Adam
Adam le 23 Sep 2016
Modifié(e) : Adam le 23 Sep 2016
a = zeros(3);
b = padarray( a, [1 1], 1 );
would put 1s all the way round, but this produces a 5x5 matrix. A 4x4 matrix result is ambiguous without being more clearly defined.
Note: This requires the Image Processing Toolbox though
  1 commentaire
Offroad Jeep
Offroad Jeep le 23 Sep 2016
worked Thanks

Connectez-vous pour commenter.

Catégories

En savoir plus sur Image Processing Toolbox dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by