필터 지우기
필터 지우기

Info

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

Error: Subscript indices must either be real positive integers or logicals

조회 수: 1 (최근 30일)
Santtu Söderholm
Santtu Söderholm 2016년 9월 24일
마감: MATLAB Answer Bot 2021년 8월 20일
The following code produces the error in the title:
syms x;
% Alkuarvoja
n = 100;
P = 0.02;
lambda = n*P; % Poissonin parametri
% Tiheysfunktiot
b(x) = nchoosek(n,x) * P^x * (1-P)^(n-x); % Binomi
p(x) = (lambda^(x))/(exp(-lambda) * factorial(x)); % Poisson
% Todennäköisyydet
Pb = 0; % Binomi
Pp = 0; % Poisson
% Binomilaskenta
for i = 0:1:2
Pb = Pb + b(i);
end
% Poissonin approksimaatio
for i = 0:1:2
Pp = Pp + P(i);
end
Pp = 1 - Pp;
Pb = vpa(Pb);
Pp = vpa(Pp);
disp(Pb)
disp(Pp)
Any idea what might be causing it?

답변 (1개)

Walter Roberson
Walter Roberson 2016년 9월 24일
You have
for i = 0:1:2
Pp = Pp + P(i);
end
MATLAB is case sensitive, so the P there refers to
P = 0.02;
not to
p(x) = (lambda^(x))/(exp(-lambda) * factorial(x)); % Poisson
We recommend avoiding using different variables that differ only in uppercase / lowercase: you can certainly do that and sometimes there are good reasons to do it, but unless there are good reasons the practice is more likely to lead to exactly this kind of confusion.

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

제품

Community Treasure Hunt

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

Start Hunting!

Translated by