Error: Index exceeds array bounds.
조회 수: 3 (최근 30일)
이전 댓글 표시
Hi,
I have read multiple posts related to the subject error but couldn't find the answer related to my query. Any help is much appreciated.
I have an excel file (256x2) and I am reading it in MATLAB with xlsread. The task is to find a number (coming from an input data array) in the first column and locate its neighbouring second column entry. I am doing it by following way.
V = Excel_file(Excel_file(:,1) == Column1(i),:);
modTemp=V(2);
After locating the respective entry, subtract it from 256 and store the result in mod_cal variable which is also declared as an array.
mod_cal(i)=256-modTemp;
The code is doing fine uptill here. Problem begins in the next part. I have to find the mod_cal variable's value in the second column now and whatever its respective neighbouring entry would be in the first column, i need to read it in an array named mod_MulInverse and that is going to be my result.
W = Excel_file(Excel_file(:,2) == mod_cal(i),:);
mod_MulInverse(i)=W(1);
Complete code is as follows.
mod_cal=zeros(1, 256);
mod_MulInverse=zeros(1, 256);% for storing the values with 256-col2
Excel_file = xlsread('powerValues.xlsx');
for i=1:256 % see excell, we want to go from 0 to 256 (Exclude first 2 entries)
if(Column1(i)==0 || Column1(i)==1) %OR condition
mod_cal(i)=Column1(i);
mod_MulInverse(i)=Column1(i);
else
V = Excel_file(Excel_file(:,1) == Column1(i),:);
modTemp=V(2);
mod_cal(i)=256-modTemp; %256-alphapower
W = Excel_file(Excel_file(:,2) == mod_cal(i),:);
mod_MulInverse(i)=W(1);
end
end
The first part works fine, I get an error for the second part which says that the index exceeds array bounds for mod_MulInverse(i)=W(1) line.
Please help me understand the issue here and resolve the error.
Thank you !
댓글 수: 0
답변 (1개)
Sudharsana Iyengar
2021년 11월 16일
Can you check the Size of W. and see what W(1) contains.
mod_MulInverse(i)=Column1(i); %working
mod_MulInverse(i)=W(1);% not working Are you sure for all values you want to store W(1) only.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Spreadsheets에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!