필터 지우기
필터 지우기

Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

Error regarding matrix indices while iterating through loop

조회 수: 1 (최근 30일)
Panth Patel
Panth Patel 2020년 10월 31일
마감: MATLAB Answer Bot 2021년 8월 20일
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.

답변 (1개)

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

이 질문은 마감되었습니다.

Community Treasure Hunt

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

Start Hunting!

Translated by