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 Comments

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..

Sign in to comment.

 Accepted Answer

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 Comments

i dont really know actually :(
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?
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?

Sign in to comment.

More Answers (0)

Tags

No tags entered yet.

Asked:

on 21 Dec 2015

Edited:

on 31 Dec 2015

Community Treasure Hunt

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

Start Hunting!