sum of array by specific index value
Ältere Kommentare anzeigen
hi, i have two array. First array containing index and second array (hasil_tambah_array) containing the value to be sum-up as below:
index =
4
2
4
hasil_tambah_array =
3.6881
0.8506
0.0132
0.8506
10.5147
12.5147
14.5074
21.8003
11.2145
18.5074
I try to sum the second array as per index such as 3.6881,0.8506,0.0132 and 0.8506 (since the 1st index is 4) will be sum together . Then 10.5147 and 12.5147 (since the 2nd index is 2) will be sum up and respectively (next will be the rest since the index is 4).
Appreciate ur time to solve this. TQIA.
Akzeptierte Antwort
Weitere Antworten (1)
KALYAN ACHARJYA
am 29 Mai 2021
Bearbeitet: KALYAN ACHARJYA
am 29 Mai 2021
result=sum(second_arary(first_array))
More
result=sum(hasil_tambah_array(index))
2 Kommentare
Khairul Nur
am 29 Mai 2021
Bearbeitet: Khairul Nur
am 29 Mai 2021
KALYAN ACHARJYA
am 29 Mai 2021
Bearbeitet: KALYAN ACHARJYA
am 29 Mai 2021
index =[4
2
4];
hasil_tambah_array =[3.6881
0.8506
0.0132
0.8506
10.5147
12.5147
14.5074
21.8003
11.2145
18.5074];
result=sum(hasil_tambah_array(index))
Output:
result =
2.5518
More: Same as
>> 0.8506+0.8506+0.8506
ans =
2.5518
Kategorien
Mehr zu Matrix Indexing finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!