Sum in Loop in Array
Mostra commenti meno recenti
Hi,
I have currency matrix and weights, ccy = [1 2 3 2 2 2 1] weight = [25 67 56 63 89 24 90; 67 34 83 54 32 12 90]
wanted to sum according to currency i.e. out exposure is matrix of 2 X 3 exposure matrix corresponding to ccy (1 2 3) = [115 243 56;157 132 83]
Tried using sum function but not able to refer to particular row in weight matrix.
Can someone please let me know what will be the correct way of doing it
Thanks
2 Commenti
KSSV
il 17 Apr 2017
Your question is not clear. ccy and weight is okay, what is this [115 243 56;157 132 83] ?
Sujata Bhadana
il 17 Apr 2017
Risposte (1)
>> [accumarray(ccy(:),weight(1,:).'),accumarray(ccy(:),weight(2,:).')].'
ans =
115 243 56
157 132 83
2 Commenti
Sujata Bhadana
il 17 Apr 2017
Modificato: Stephen23
il 17 Apr 2017
Stephen23
il 17 Apr 2017
@Sujata Bhadana: you spelled the function name incorrectly. It should be accumarray, not accumarry.
Categorie
Scopri di più su Loops and Conditional Statements in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!