MATLAB: Subscript indices must either be real positive integers or logicals.

change point analysismann whitney test

Hello everyone! I am trying to run a Mann Whitney test using the following script
w = [10];
for k = 1:length(w)
na = w(k);
nb = w(k);
for i = w(k)/2+1:length(k)-w(k)/2
[p,h] = ranksum(k(i-w(k)/2:i-1),k(i+1:i+w(k)/2));
mwreal(k,i) = p;
end
mwreal(k,1:w(k)/2) = mwreal(k,w(k)/2+1) * ones(1,w(k)/2);
mwreal(k,length(k)-w(k)/2) * ones(1,w(k)/2);
end
Then, when I run the script I get the following mistake:
Error in (line 318)
mwreal(k,length(k)-w(k)/2) * ones(1,w(k)/2);
I already change the name of the variable "k" to discard any name duplication. The variable k correspond to interpolated data (all positive and ranging between 6.2 and 7.6). I am not a MatLab expert so please if you can help me with this it will be much appreciated. Thanks in advance
Salomé

Best Answer

Lets have a look at that line:
mwreal(k,length(k)-w(k)/2)
k is the scalar loop variable, which means that
length(k) == 1
And w is defined as a scalar with value ten, so
1 - 10/2 == -4
is what you are attempting to use as an index, and clearly -4 is not a positive integer or a logical, which are required for indexing.
That line currently serves no purpose, as its value is not allocated to anything.
Related Question