Info

Cette question est clôturée. Rouvrir pour modifier ou répondre.

Error regarding matrix indices while iterating through loop

1 vue (au cours des 30 derniers jours)
Panth Patel
Panth Patel le 31 Oct 2020
Clôturé : MATLAB Answer Bot le 20 Août 2021
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.

Réponses (1)

Shubham Khatri
Shubham Khatri le 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

Cette question est clôturée.

Community Treasure Hunt

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

Start Hunting!

Translated by