Borrar filtros
Borrar filtros

Error: Index exceeds array bounds.

5 visualizaciones (últimos 30 días)
Maryam Idrees
Maryam Idrees el 16 de Nov. de 2021
Respondida: Sudharsana Iyengar el 16 de Nov. de 2021
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),:);
After locating the respective entry, subtract it from 256 and store the result in mod_cal variable which is also declared as an array.
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),:);
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
V = Excel_file(Excel_file(:,1) == Column1(i),:);
mod_cal(i)=256-modTemp; %256-alphapower
W = Excel_file(Excel_file(:,2) == mod_cal(i),:);
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 !

Respuestas (1)

Sudharsana Iyengar
Sudharsana Iyengar el 16 de Nov. de 2021
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.




Community Treasure Hunt

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

Start Hunting!

Translated by