Info
This question is closed. Reopen it to edit or answer.
??? Subscript indices must either be real positive integers or logicals.
1 view (last 30 days)
Show older comments
Hello. Could someone help me with this please. This code works fine until I change either the frequency values freq1 and freq2 and/or the values in the r=round((freq1+freq2)/(freq2-freq1)+1)/round((freq1+freq2)/(freq2-freq1)-1); to values other than unity i.e. introducing 2* in r=round(2*(freq1+freq2)/(freq2-freq1)+1)/round(2*(freq1+freq2)/(freq2-freq1)-1); sometimes gives the error ??? Subscript indices must either be real positive integers or logicals.
Here is the full script.
fs = 48000;
buf_dur = 1;
freq1=880;
freq2=880*(81/64);
r=round((freq1+freq2)/(freq2-freq1)+1)/round((freq1+freq2)/(freq2-freq1)-1);
[p_1,q_1]=numden(sym(r));
p=double(sym(p_1));
q=double(sym(q_1));
buf=sin(linspace(0,2*pi*freq1*buf_dur,buf_dur*fs))+sin(linspace(0,2*pi*freq2*buf_dur,buf_dur*fs));
plot([0:fs*buf_dur-1],buf)
hold
sound(buf,fs)
n = (freq2-freq1).*freq1.*buf_dur;
k = round((freq1+freq2)*abs(((4*(1:n)+1)-2)/(4*(freq2*q-p*freq1))));
m = round((freq1+freq2)*abs(((4*(1:n)-1)-2)/(4*(freq2*q-p*freq1))));
t_1 = (2*m - 1)/(2*(freq1+freq2));
t_2 = (2*k - 1)/(2*(freq1+freq2));
t_1a = t_1(find(t_1 < buf_dur));
t_1b=round(t_1a*fs);
plot(t_1b,buf(t_1b),'.r')
t_2a = t_2(find(t_2 < buf_dur));
t_2b=round(t_2a*fs);
plot(t_2b,buf(t_2b),'.r')
axis([0 10000 -2.5 2.5])
buf2=zeros(1,fs*buf_dur);
buf2(round(t_1b))=2;
buf2(round(t_2b))=2;
sound(buf2,fs)
sound([buf,buf2],fs)
I've managed to determine that the error starts at t_1a = t_1(find(t_1 < buf_dur)); I'm still learning the basics so any help would be greatly appreciated.
Many thanks
2 Comments
Image Analyst
on 16 Dec 2012
rick, I see you tried to edit your posting. When you edit, you don't need to have blank lines between lines to get them to show up on separate lines. Just paste in your code, highlight it all, and click the {}Code button above. It will look fine if you do that. I've fixed it for you.
Answers (3)
Image Analyst
on 16 Dec 2012
If this is your code
t_1a = t_1(find(t_1 < buf_dur));
the index would be
find(t_1 < buf_dur)
but that returns either integers or empty. but the t1_a line would still execute even if it's empty (I tried it with sample data). So we'd need more info. Are you using the debugger? If you knew how to use that, you'd have this solved very quickly.
0 Comments
Roger Stafford
on 16 Dec 2012
Edited: Walter Roberson
on 16 Dec 2012
In the definition "t_1a = t_1(find(t_1 < buf_dur));" you have ensured that no index in 't_1b' could exceed 'fs' which is the length of 'buf', so the error cannot be due to an excessive index in "buf(t_1b)". However, I see nothing here that prevents a zero value in 't_1b', which would also produce an error message there. A zero would occur there if an 'm' value were zero, or if an 'm' were 1 and freq1+freq2 were too large (a number less than one-half will round down to zero.)
Roger Stafford
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!