How to resolve the "Index exceeds matrix dimensions" error ?

clear all;
clc;
s=input('Please input a watermark made up by 26 small English letters : ','s');
ss=input('Select the original sound file in the form of *.wav : ','s');
watermarkedfile=input('Type in the name of watermarked sound file in the form of *.wav : ','s');
watermark=wm(s);
alpha=0;
[x fs]=wavread(ss);%read the wave film
x=x';
seg1=enframe(x,885); % each frame is 20ms, 500 frames in total
for i=1:1:500;
if watermark(1,i)==1
temp(i,:)=fft2(seg1(i,:));
[r,c]=find(temp(i,:)==max(temp(i,:)));
if c(1)+1<=855 && c(1)>=1
temp(i,c(1)+1)=temp(i,c(1)+1)*alpha;
elseif c(1)+1>855
temp(i,c(1)-1)=temp(i,c(1)-1)*alpha;
end
else if watermark(1,i)==0
temp(i,:)=fft2(seg1(i,:));
end
end
end
for i=1:1:500;
if watermark(1,i)==1
temp1(i,:)=ifft2(temp(i,:));
end
if watermark(1,i)==0
temp1(i,:)=ifft2(temp(i,:));
end
end
temp1=real(temp1');
out=temp1(:);
out=mapminmax(out);
for i=1:1:length(out)% the following two loops avoid data overflow
if out(i)>=1
out(i)=0.99996948242188;
end
end
for i=1:1:length(out)
if out(i)<=-1
out(i)=-0.99996948242188;
end
end
display('Watermarked file created:');
display(watermarkedfile);
fs=44100;
wavwrite(out',fs,watermarkedfile);
y=x(1,1:length(out))';
snr=10*log10(sum(y.^2)/sum((y-out).^2));
display(snr);
display('Would you like to hear the sound after watermarking?');
display('please input y/n');
k=input('','s');
if k(1)=='y';
sound(out,44100);
elseif k(1)~='y' && k(1)~='n';
display('input error');
end
datacer1 = s;
save cerr.mat datacer1;

4 comentarios

Can you please post all of the error message. This means all of the red text. Your code has many places that use indexing, and our mind-reading ability is not very good these days, so you actually need to tell us where the error is occurring.
Index exceeds matrix dimensions.
Error in freq (line 50) y=x(1,1:length(out))';
that is all of the red text :(
anyone can explain me about how my audio watermarking source code can work?i still dont understand about the embedding proccess, please help me..

Iniciar sesión para comentar.

 Respuesta aceptada

James Tursa
James Tursa el 21 de Dic. de 2015
Editada: James Tursa el 21 de Dic. de 2015
Type the following at the command line:
dbstop if error
Then run your program. When the error occurs, the program will pause at the line that is causing the error. All of the workspace variables present at that time will be available for you to examine to determine the cause of the error. (e.g., maybe your for loop indexing is not correct, or one of the variable sizes is not what you expected it to be, etc.)

6 comentarios

i dont really know actually :(
James Tursa
James Tursa el 21 de Dic. de 2015
Editada: James Tursa el 21 de Dic. de 2015
You don't really know what? What line does the program pause at? What is the entire error message? What is the size of x and what is the size of out?
yeah i see that line, but i dont know to fix it :(
Apparently, length(out) is bigger than the number of columns of x. Is that supposed to be the case?
Stephen23
Stephen23 el 22 de Dic. de 2015
Editada: Stephen23 el 31 de Dic. de 2015
Many beginners use length without realizing that its output gives the size of the largest dimension:
max(size(X))
This can lead to unexpected behavior when the input array has a significantly different aspect ratio.
I would recommend avoiding length entirely, and using numel and size instead (the latter has a dimension argument).
anyone can explain me about how my audio watermarking source code can work?

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Etiquetas

Aún no se han introducido etiquetas.

Preguntada:

el 21 de Dic. de 2015

Editada:

el 31 de Dic. de 2015

Community Treasure Hunt

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

Start Hunting!

Translated by