Effacer les filtres
Effacer les filtres

Adding zeros to a matrix to match the dimensions of two matrices.

50 vues (au cours des 30 derniers jours)
ammara khurshid
ammara khurshid le 27 Nov 2017
Commenté : ammara khurshid le 2 Déc 2017
Hi ! need help to match the size of two matrices. I have two matrices of dimensions mxn and jxk. I want make mxn of size jxk by adding zeros at the end of the mxn. A of mxn dimenssion and B of jxk dimenssion. Am doing by this way:
newA=[A,zeros(size(B)]
  1 commentaire
ammara khurshid
ammara khurshid le 27 Nov 2017
Modifié(e) : ammara khurshid le 27 Nov 2017
I want size(newA)=size(B) but this way it becomes size(newA)>size(B). kindly urgent help needed.

Connectez-vous pour commenter.

Réponse acceptée

Guillaume
Guillaume le 27 Nov 2017
newA = [A, zeros(size(A, 1), size(B, 2)-size(A, 2)); zeros(size(B, 1)-size(A, 1), size(B, 2))];
Assuming that both dimensions of B are greater than A.

Plus de réponses (1)

James Tursa
James Tursa le 27 Nov 2017
Another way:
newA = zeros(size(B));
newA(1:size(A,1),1:size(A,2)) = A;
  2 commentaires
Guillaume
Guillaume le 27 Nov 2017
Yes, actually simpler than my answer. And in case A is not of class double:
newA = zeros(size(B), 'like', A);
ammara khurshid
ammara khurshid le 2 Déc 2017
Thank you

Connectez-vous pour commenter.

Catégories

En savoir plus sur Logical 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