"Index in position 1 is invalid. Array indices must be positive integers or logical values."
2 次查看(过去 30 天)
显示 更早的评论
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 个评论
Rik
2019-2-7
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
2019-2-7
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.
回答(1 个)
Preethi
2019-2-8
Initialize variable i with 1, before using it
i=1;
2 个评论
Rik
2019-2-8
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.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!