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

KSSV
KSSV 2017년 4월 17일
Your question is not clear. ccy and weight is okay, what is this [115 243 56;157 132 83] ?
Sujata Bhadana
Sujata Bhadana 2017년 4월 17일
This is the final output I am looking for

댓글을 달려면 로그인하십시오.

답변 (1개)

Stephen23
Stephen23 2017년 4월 17일
편집: Stephen23 2017년 4월 17일

0 개 추천

>> [accumarray(ccy(:),weight(1,:).'),accumarray(ccy(:),weight(2,:).')].'
ans =
115 243 56
157 132 83

댓글 수: 2

Sujata Bhadana
Sujata Bhadana 2017년 4월 17일
편집: Stephen23 2017년 4월 17일
Thanks Stephen, this seems to be working if I provide output array in element form mentioned by you but is not working in loop
exposure = zeros(1000,3);
for i = 1:1000
exposure(i,:) = accumarry(ccy(:),weight(1,:)).';
end
I am running in loop as number of Row in final output is in 1000 but getting the below error Undefined function 'accumarry' for input arguments of type 'double'.
Stephen23
Stephen23 2017년 4월 17일
@Sujata Bhadana: you spelled the function name incorrectly. It should be accumarray, not accumarry.

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

질문:

2017년 4월 17일

편집:

2017년 4월 17일

Community Treasure Hunt

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

Start Hunting!

Translated by