필터 지우기
필터 지우기

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);
  댓글 수: 2
KSSV
KSSV 2022년 7월 21일
Which line is trhowing error? Copy and paste the full error lines here.
farhah muhammad
farhah muhammad 2022년 7월 21일
Error in pvalue (line 5)
x = listAKI.PatientStruct.Greal(:,AKI);
Error using dbcont
Debug commands only allowed when stopped in debug mode.

댓글을 달려면 로그인하십시오.

답변 (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