operation between 2 vectors by Indexing
2 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Dear, I looking to doing a operation (summation for example) between two vectors but the elements indexing are stored in others two vectors:
vectors to summation
A = [10 25 12.5 4 -7.5];
B = [0.05 33.5 -20 12.25 0.65];
Indexing vectors
Aind = [1 4 5 4]; % index for A vector
Bind = [3 2 1 5]; % index for B vector
for result i must have
C(1) = A(1)+B(3) = 10+(-20)
C(2) = A(4)+B(2) = 4+33.5
C(3) = A(5)+B(1) = -7.5+0.05
C(4) = A(4)+B(5) = 4+0.65
I am blocked
for i = 1 : length(Aind)
C(i) = A(Aind ?)+B(Bind ?)
end
0 Commenti
Risposte (1)
Star Strider
il 8 Apr 2017
No loop necessary. You have all the infromation you need in ‘A’, ‘B’, and the index vectors:
C = A(Aind) + B(Bind)
C =
-10 37.5 -7.45 4.65
0 Commenti
Vedere anche
Categorie
Scopri di più su Matrix Indexing in Help Center e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!