Info
此问题已关闭。 请重新打开它进行编辑或回答。
Error regarding matrix indices while iterating through loop
1 次查看(过去 30 天)
显示 更早的评论
v = [10 20 40 60 80 100];
N = 10:5:100;
for j=1:length(v)
pb(j) = (1/2)*(erf(((s-d)/v(j) - mu_t)/(sqrt(2)*sigma_t)) - erf(((r-d)/v(j) - mu_t)/(sqrt(2)*sigma_t)));
for i=1:length(N)
qm(i,j) = qfunc((K - N(i)*PM)/sqrt(N(i)*PM*(1 - PM)))*pb(j);
end
end
Having this error
Unable to perform assignment because the indices on the left side are not compatible with the size of the right side.
0 个评论
回答(1 个)
Shubham Khatri
2020-11-9
I tried reporducing this on my end. It seems to have worked fine when I have assumed the values of some variables as shown below. With these assumptions, the code worked. Although, please check the values for the qfunc as it takes only real valued inputs. You can find more info on qfunc here.
clc
clear
v = [10 20 40 60 80 100];
N = 10:5:100;
s=5;
d=2;
mu_t=1;
sigma_t=2;
r=3;
K=4;
PM=0.7;
for j=1:length(v)
pb(j) = (1/2)*(erf(((s-d)/v(j) - mu_t)/(sqrt(2)*sigma_t)) - erf(((r-d)/v(j) - mu_t)/(sqrt(2)*sigma_t)))
for i=1:length(N)
qm(i,j) = qfunc((K - N(i)*PM)/sqrt(N(i)*PM*(1 - PM)))*pb(j)
end
end
0 个评论
此问题已关闭。
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!