How to resolve the "Index exceeds matrix dimensions" error ?
Mostrar comentarios más antiguos
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
Stephen23
el 21 de Dic. de 2015
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.
ben kang
el 21 de Dic. de 2015
ben kang
el 21 de Dic. de 2015
ben kang
el 29 de Dic. de 2015
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Matrix Indexing en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!