How to fix: Index Exceeds Matrix Dimensions
1 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
回答(1 个)
Abraham Boayue
2018-3-18
编辑:Abraham Boayue
2018-3-20
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?
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!