How can I add the elements of a smaller matrix in the elements of a bigger matrix at some specified locations ???
10 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Asif Arshid
le 25 Juil 2017
Commenté : Asif Arshid
le 25 Juil 2017
Is there any direct way of adding matrix "B" directly in "A" to get "D" matrix ??? I did it the following way...
A=ones(5);
B=ones(2);
C=zeros(5);
C(1:2,1:2)=B;
D=C+A;
0 commentaires
Réponse acceptée
James Tursa
le 25 Juil 2017
Modifié(e) : James Tursa
le 25 Juil 2017
Another way:
D = A;
D(1:2,1:2) = D(1:2,1:2) + B;
Or, if you don't know the size of B in advance or where you want it added in:
i = row index of replacement spot
j = col index of replacement spot
[m,n] = size(B);
D = A;
D(i:i+m-1,j:j+n-1) = D(i:i+m-1,j:j+n-1) + B;
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Matrix Indexing 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!