I AM GETTING INDEX EXCEEDS MATRIX DIMENSIONS error? PLEASE HELP?
Afficher commentaires plus anciens
The following code is used for digital image watermarking using the feature points of the cover image I am getting the following error: Index exceeds matrix dimensions. Error in Algo1 (line 115) M(i1,j1)=a1(i1,j1); Please tell me how to resolve this error code (m file attached for reference)
6 commentaires
Stephen23
le 13 Nov 2017
@Aniket Paranjpe: That code is very badly aligned and indented. Badly aligned code is one way that beginners hide code errors. You should use the MATLAB editor's default alignment settings. You can also align the code in the editor by selecting all text and then clicking ctrl+i.
You also need to write comments and clearly explain what the code does.
Aniket Paranjpe
le 14 Nov 2017
Jan
le 14 Nov 2017
The failing line
Error in Algo1 (line 115) M(i1,j1)=a1(i1,j1)
does not occur in the posted code. So how could we fix a problem in the code, if you post a different one?
Aniket Paranjpe
le 15 Nov 2017
Walter Roberson
le 15 Nov 2017
Unfortunately we do not have lena.bmp or watermark.png to test with.
Aniket Paranjpe
le 18 Nov 2017
Réponse acceptée
Plus de réponses (2)
Jan
le 13 Nov 2017
Start with an auto-indentation to make the code readable: Ctrl-A Ctrl-I. Omit the brute clearing header "clc; close all; clear all;" - there is no reason to clear e.g. all loaded function from the RAM and waste time with reloading from the slow disk.
I cannot run your code due to missing input data and toolboxes.
The code looks strange:
for i1=1:l1
for j1=1:m1
temp=i1+(i-1)*l1;
temp1=j1+(j-1)*m1;
M(i1,j1)=a1(i1,j1);
end
end
What is the reason for overwriting temp and temp1 in each iteration? This would be much simpler:
M = a(1:l1, 1:m1);
But you should get the same error: Obviously a has either less than l1 rows or less than m1 columns. You can find out the details using the debugger:
dbstop if error
Then run the code again. When it stops, check the current values of i1 and j1 as well as the dimension of a1.
The missing comments impede the clarity of the code massively. I would not dare to debug this code or use it.
1 commentaire
Aniket Paranjpe
le 14 Nov 2017
Aniket Paranjpe
le 27 Nov 2017
Modifié(e) : Walter Roberson
le 27 Nov 2017
Catégories
En savoir plus sur Matrix Indexing dans Centre d'aide et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!