Subscripted assignment dimension mismatch
1 view (last 30 days)
Show older comments
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 Comments
Accepted Answer
Thorsten
on 17 Dec 2014
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 Comments
Guillaume
on 17 Dec 2014
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.
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!