# Attempted to access key(2,0); index must be a positive integer or logical.

2 views (last 30 days)
MU on 13 Feb 2013
Hello, everyone, i was stuck in one source code line, and i really do not understand how to fix it. here is the source code
plot(y);
tsamp = 0.01;
t = linspace(0,tsamp,tsamp*fs+1);
M = length(t);
N = floor(length(y)/M);
ys = reshape(y(1:(N*M)),M,N);
fL = [697 770 852 941];
fH = [1209 1336 1477 1633];
omega = 2*pi*fL';
w = exp(1j*omega*t);
yL = abs(w*ys)/M;
plot(yL');
omega = 2*pi*fH';
w = exp(1j*omega*t);
yH = abs(w*ys)/M;
plot(yH');
ndx = 1:4; y1 = ndx*(yL>0.07);
subplot(2,1,1);
plot(y1);
ylabel('low freq index');
subplot(2,1,2);
y2 = ndx*(yH>0.07);
plot(y2);
ylabel('high freq index');
ndx = find(diff(y1)>0);
n1 = y1(ndx+2);
n2 = y2(ndx+2);
[n1' n2']
key = ['147*'; '2580'; '369#'; 'ABCD'];
for k=1:length(n1) pn(k) =key(n2(k),n1(k));
end
disp('phone number:');
disp(pn);
the system says the error is "Attempted to access key(2,0); index must be a positive integer or logical."||
Thanks ~

Image Analyst on 13 Feb 2013
Your second index to the key array is zero. That's not allowed. I don't know WHY it is zero - we'll let you figure that out, which you can easily do if you know how to use the debugger.
##### 2 CommentsShowHide 1 older comment
Image Analyst on 14 Feb 2013