adding two matrices of unequal length

2 vues (au cours des 30 derniers jours)
Tanveer ul haq
Tanveer ul haq le 18 Juil 2021
Réponse apportée : Rik le 18 Juil 2021
I have two large matrices having different rows. for instanc, consider:
A=[1 2; 3 4; 5 6; 7 8; 9 0];
B=[7 5; 2 3];
Result=[8 7; 5 7; 12 11; 9 11; 16 5]
Now i want to add A and B such that: 1st row add with 1st, 2nd row with 2nd, 3rd row with 1st again, 4th row with 2nd again and so on. the process repeat till end.
Thanks in advance.

Réponse acceptée

Rik
Rik le 18 Juil 2021
Result=A+B(1+mod(1:size(A,1),end-1),:);
(written on mobile, untested code)

Plus de réponses (0)

Catégories

En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

Produits


Version

R2017a

Community Treasure Hunt

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

Start Hunting!

Translated by