Filter löschen
Filter löschen

Info

Diese Frage ist geschlossen. Öffnen Sie sie erneut, um sie zu bearbeiten oder zu beantworten.

Error regarding matrix indices while iterating through loop

1 Ansicht (letzte 30 Tage)
Panth Patel
Panth Patel am 31 Okt. 2020
Geschlossen: MATLAB Answer Bot am 20 Aug. 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.

Antworten (1)

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

Diese Frage ist geschlossen.

Community Treasure Hunt

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

Start Hunting!

Translated by