How do I sum a vector (row) to a matrix?
4 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
JOSUE PÁNCHEZ
le 16 Nov 2021
Commenté : Star Strider
le 16 Nov 2021
If I have
A=[1 0 0 1;
-1 0 1 1;
1 1 1 1]
B=[1 2 2 1]
How do I add the vector B to the 1st row of A so I get:
A=[2 2 2 3;
-1 0 1 1;
1 1 1 1]
0 commentaires
Réponse acceptée
Star Strider
le 16 Nov 2021
This involves a bit of indexing.
Note that the rest of ‘A’ is unchnaged, and onlly ‘A(1,:)’ is involved in the operation.
A=[1 0 0 1;
-1 0 1 1;
1 1 1 1];
B=[1 2 2 1];
A(1,:) = A(1,:) + B
.
2 commentaires
Plus de réponses (1)
the cyclist
le 16 Nov 2021
Modifié(e) : the cyclist
le 16 Nov 2021
A=[1 0 0 1;
-1 0 1 1;
1 1 1 1];
B=[1 2 2 1];
A(1,:) = A(1,: ) + B
Voir également
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!