필터 지우기
필터 지우기

problem in command window : "Subscript indices must either be real positive integers or logicals"

조회 수: 2 (최근 30일)
how do i resolve this??
function [ x] = zignrinv(c )
v=9.91256303526217e-3;
r=3.442619855899;
x(0)=(v/(nrmlpdf( r )));
x(1)=r;
x(c)=0;
for i=2:c
x(i)=sqrt(-2*log((v/x(i-1))+nrmlpdf(x(i))))
end
for i=0:c
zigr(i) =(x(i+1)/x(i));
end
end
and the function "nrmlpdf" is as folows;
function [ y ] = nrmlpdf( x )
y=exp(-x^2/2);
end

채택된 답변

Steven Lord
Steven Lord 2021년 8월 21일
There's no such thing as element 0 of an array in MATLAB. The first element of an array is element 1. Therefore line 4 of your function cannot work.
Modify your code so it uses 1-based indexing not 0-based indexing.
  댓글 수: 3
Steven Lord
Steven Lord 2021년 8월 21일
The last element of x to which your first for loop assigns is x(c). Your second for loop tries to access x(c+1) which doesn't exist. As written the last element you could create in the vector zigr is element zigr(c-1).
If x was a 5 element vector:
x = 1:5;
what would you expect zigr(5) to be and why? zigr(4) would be 5/4.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by