"Index in position 1 is invalid. Array indices must be positive integers or logical values."

1 visualización (últimos 30 días)
I get the entitled error when ever i run the code below
nu=sum((i-(n+1)/2).*Y(i,:)
for the equation
and also the same error for
de=sqrt(n^3*(sum(Y(i,:)-mean(Y(i,:)))^.2))
for the equation
where first is the numerator and second is the denominator of D, "test for normality was given by D’Agostino"
full code
y1=[51 27 37 42 27 43 41 38 36 26 29]';
y2=[36 20 22 36 18 32 22 21 23 31 20]';
y3=[50 26 41 32 33 43 36 31 27 31 25]';
y4=[35 17 37 34 14 35 25 20 25 32 26]';
y5=[42 27 30 27 29 40 38 16 28 36 25]';
Y=[y1 y2 y3 y4 y5]
Y=sort(Y)
[n p]=size(Y)
nu=sum((i-(n+1)/2).*Y(i,:))
de=sqrt(n^3*(sum(Y(i,:)-mean(Y(i,:)))^.2))
D=nu./de
YY=sqrt(n)*(D-inv(2*sqrt(pi)))/0.02998598
  2 comentarios
Rik
Rik el 7 de Feb. de 2019
Without the full code you are using it is difficult to provide a working solution. Try to make a MWE so we can run your code without any other dependencies and can reproduce your issue.
Currently it is not possible to tell if you are shadowing the sum function with a variable named sum, or if your i variable is not properly defined.
Rik
Rik el 7 de Feb. de 2019
You didn't define i yourself, so now Matlab treats it as the imaginary unit. I don't have a clue what you're trying to do, but it seems you should read the documentation for the symbolic computation toolbox, or rewrite your expression to a normal Matlab computation.

Iniciar sesión para comentar.

Respuestas (1)

Preethi
Preethi el 8 de Feb. de 2019
Initialize variable i with 1, before using it
i=1;
  2 comentarios
Rik
Rik el 8 de Feb. de 2019
Although this modification will make this code run without error, this will not return the solution for the mathematical expression. I don't understand the notation (specifically the equal sign inside the sum), but I'm sure this will not solve the problem.
Mustafa Kamal
Mustafa Kamal el 8 de Feb. de 2019
now i have made some changes in the code however i is giving wrong answer
y1=[47.8,46.4,46.3,45.1,47.6,52.5,51.2,49.8,48.1,45.0,51.2,48.5,52.1,48.2,49.6,50.7,47.2,53.3,46.2,46.3]';
y2=[48.8,47.7,46.8,45.3,48.5,53.2,53,50,50.8,47,51.4,49.2,52.8,48.9,50.4,51.7,47.7,54.6,47.5,47.6]';
y3=[49,47.7,47.8,46.1,48.9,53.3,54.3,50.3,52.3,47.3,51.6,53,53.7,49.3,51.2,52.7,48.4,55.1,48.1,51.3]';
y4=[49.7,48.4,48.5,47.2,49.3,53.7,54.5,52.7,54.4,48.3,51.9,55.5,55,49.8,51.8,53.3,49.5,55.3,48.4,51.8]';
Y=[y1 y2 y3 y4];
Y=sort(Y)
n=length(Y)
T=[];
W=[];
for i=1:n
T=[T; ((i-(n+1)/2).*Y(i,:))]
W=[W; sqrt(n^3*((Y(i,:)-mean(Y)).^2))]
end
nu=sum(T)
de=sum(W)
D=nu./de
YY=sqrt(n).*(D-inv(2*sqrt(pi)))./0.02998598
where are the correct answer for the above question is
D=[.2848 .2841 .2866 .2851]
and
YY=[.4021 .2934 .6730 .4491]
please help anyone to resolve my issue.

Iniciar sesión para comentar.

Categorías

Más información sobre Matrix Indexing 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