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

1 visualización (últimos 30 días)
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

Respuesta aceptada

Steven Lord
Steven Lord el 21 de Ag. de 2021
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 comentarios
Steven Lord
Steven Lord el 21 de Ag. de 2021
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.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Matrices and Arrays en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by