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

1 次查看(过去 30 天)
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);

回答(1 个)

Shivani
Shivani 2023-10-18
编辑:Shivani 2023-10-19
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!

类别

Help CenterFile Exchange 中查找有关 Matrix Indexing 的更多信息

产品


版本

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by