Subscripted assignment dimension mismatch
조회 수: 1 (최근 30일)
이전 댓글 표시
Hello! I have the following problem: Matlab tells me there is a "subscripted assignment dimension mismatch". This the code I'm trying to run:
N = 1:20;
extrapolatedmaturities = 1:100;
Price = zeros(s,length(extrapolatedmaturities));
for t = 1:s
for i = 1:length(extrapolatedmaturities)
Price(t,:) = exp(-UFR*i)+...
(z(:,t)'*SWfunction(N,maturities2,alpha,UFR));
end
end
Where UFR is a number, z is a N by t matrix (which I invert) and SWfunction produces a N by N matrix. What I want matlab to do is to produce a t by i matrix where for all columns it computes exp(-UFR*i) and up to N add it to the second term, in which it should take for each t the row of values in z, multiply it by the NxN matrix from the SWfunction. Can someone help me? I've tried so many ways of doing this and it always tells me there is a dimension mismatch...
댓글 수: 0
채택된 답변
Thorsten
2014년 12월 17일
The term exp(-UFR*i) is indepent of t, so you could compute it as
for i = 1:length(extrapolatedmaturities)
expUFR(i) = exp(-UFR*i);
end
And then use
for t = 1:s
Price(t,:) = expUFR + z(:,t)'*SWfunction(N,maturities2,alpha,UFR);
end
댓글 수: 3
Guillaume
2014년 12월 17일
And also, unless SWfunction output can change for the same input that can also be calculated once out of the loop, since it doesn't depend on t either:
expUFR = exp(-UFR*extrapolatedmaturaties)
SWvalue = SWfunction(N, maturities2, alpha, UFR);
for t = 1:s
Price(t, :) = expUFR + z(:, t)' * SWvalue;
end
And I'm sure even the t loop could be vectorised although I can't think how right now.
추가 답변 (0개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!