How can I take the values of one array, map the values as indices to another array, then generate a thrid array with the sum of former's elements??
Mostrar comentarios más antiguos
I know the question is a bit confusing, so let me illustrate what i am trying to do with an example:
A = [ 2 1 4 2 3 2 4 0 ]
B = [ 1 1.5 2 1.5 2.5 3 1 ]
Now what I need is C = [ 1.5 5.5 2.5 3 ] Here is an explanation:
A[2] = 1 , so B[2] = C[1]
A[1], A[4], A[6] = 2, so B[1]+B[4]+B[6]= C[2]
A[5] = 3 so B[5] = C[3]
A[3], A[7] = 4 so B[3]+B[5] = C[4]
The index elements from A with common values (or a particular value) are mapped to B(same indices), then the elements with those indices in B are added (if one value, directly become elements in C) to get array C such that the values of A are indices of C.
Edited: A[8] = 0, so neglect that value.
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Matrix Indexing en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!