Effacer les filtres
Effacer les filtres

How to fix: Index Exceeds Matrix Dimensions

1 vue (au cours des 30 derniers jours)
Ahmad Ali Syafi'i
Ahmad Ali Syafi'i le 18 Mar 2018
Im new to MATLAB and am trying to extract data from a aerial photo in tif.I keep getting this error:
Index exceeds matrix dimensions.
Error in STASAR>pushbutton2_Callback (line 544)
komp1(k,j)=komp1p(w,1);
And that from this editor:
komp1=zeros(801,801);
komp2=zeros(801,801);
w=0;
for i=1:801
k=801+1-i;
for j=1:801
w=w+1;
komp1(k,j)=komp1p(w,1); error from this line
komp2(k,j)=komp2p(w,1);
end
end
please help me, this is progress in my thesis. Thanks

Réponses (1)

Abraham Boayue
Abraham Boayue le 18 Mar 2018
Modifié(e) : Abraham Boayue le 20 Mar 2018
Hey Ahmad, it looks like you have created more space for the data than you are trying to store in komp1. Komp1 is sized 801 by 801, which means that your data size must be at least 801 by 801. If it is less, say 800 by 800, you will get error of index exceed matrix dimensions. This is because your double for loops were made to run 801 times. Every time they run, one data point is saved, the code will work fine as long as there is something to do. So, in short, you cannot create more space than what you have to work with. Check the size of the data and then make room for it. I don't know what you are trying to achieve with your code, but what are the aims of k and w?

Catégories

En savoir plus sur Matrix Indexing dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by