Info

Questa domanda è chiusa. Riaprila per modificarla o per rispondere.

Error regarding matrix indices while iterating through loop

1 visualizzazione (ultimi 30 giorni)
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.

Risposte (1)

Shubham Khatri
Shubham Khatri il 9 Nov 2020
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

Questa domanda è chiusa.

Community Treasure Hunt

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

Start Hunting!

Translated by