Index in position 2 exceeds array bounds. Index must not exceed 1 for ranksum looping

1 view (last 30 days)
Hi, hope everyone have good day,
I'm trying to use ranksum for my coding because ranksum can use different length for x and y. but I keep receiving this problem.
Index in position 2 exceeds array bounds. Index must not exceed 1 and do not sure why and how to fix it because the p-value for ranksum appeared in the workspace.
thank you
AKIfolder = {'A003419.mat', 'A181069.mat', 'A929060.mat', 'B651999.mat', 'B664654.mat', 'B736322.mat', 'B764581.mat', 'B777509.mat', 'B780014.mat', 'B780227.mat'};
for AKI = 1:numel(AKIfolder)
listAKI = load(AKIfolder{AKI});
x = listAKI.PatientStruct.Greal(:,AKI);
end
SNAKIfolder = {'A030769.mat', 'A128207.mat', 'A138748.mat', 'A926245.mat', 'B238568.mat', 'B441119.mat', 'B496482.mat', 'B534716.mat', 'B773960.mat', 'B777504.mat'};
for SNAKI = 1:numel(SNAKIfolder)
listSNAKI = load(SNAKIfolder{SNAKI});
y = listSNAKI.PatientStruct.Greal(:,SNAKI);
end
[p] = ranksum(x,y);
  2 Comments
farhah muhammad
farhah muhammad on 21 Jul 2022
Error in pvalue (line 5)
x = listAKI.PatientStruct.Greal(:,AKI);
Error using dbcont
Debug commands only allowed when stopped in debug mode.

Sign in to comment.

Answers (1)

Shivani
Shivani on 18 Oct 2023
Edited: Shivani on 19 Oct 2023
The error you are receiving is not because of the ranksum function. It is due to illegal memory access while indexing into the “GReal” array of the “PatientStruct. However, the exact reason causing this error is difficult to determine without looking at the contents of the files in folder “AKIfolder” and “SNAKIfolder”.
I am assuming that you were trying to access all the rows in the GReal array for every file in the folder. As mentioned in the error, index in the second position cannot exceed 1, implying that there is only one column in the GReal array. Therefore, you can modify your code as shown below:
AKIfolder = {'A003419.mat', 'A181069.mat', 'A929060.mat', 'B651999.mat', 'B664654.mat', 'B736322.mat', 'B764581.mat', 'B777509.mat', 'B780014.mat', 'B780227.mat'};
x = [];
for AKI = 1:numel(AKIfolder)
listAKI = load(AKIfolder{AKI});
x = vertcat(x, listAKI.PatientStruct.Greal(:,1));
end
SNAKIfolder = {'A030769.mat', 'A128207.mat', 'A138748.mat', 'A926245.mat', 'B238568.mat', 'B441119.mat', 'B496482.mat', 'B534716.mat', 'B773960.mat', 'B777504.mat'};
y = [];
for SNAKI = 1:numel(SNAKIfolder)
listSNAKI = load(SNAKIfolder{SNAKI});
y = vertcat(y, listSNAKI.PatientStruct.Greal(:,1));
end
Note that I have also added an extra line of code that concatenates data extracted from all files in AKIfolder" to x and data extracted from all files in SNAKIfolder to y. In the current version, x and y are being overwritten at every iteration, which ultimately defeats the purpose of the for loop.
Please refer to the link below for more information about indexing into a MATLAB array and the vertcat function:
I hope this resolves your issue!

Products


Release

R2021b

Community Treasure Hunt

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

Start Hunting!