Subscript indices must either be real positive integers or logicals.
1 view (last 30 days)
Show older comments
Hi everyone, I'm learning Matlab for university. I need your help to understand how to solve this problem. This is my script:
fc=4;
dt=1/fc;
t=0:dt:19-dt;
s=[ones(1,4*fc) zeros(1,6*fc)];
h=sin(2*pi*t2/15 + pi/4);
figure
plot([0:length(s)-1]*dt,s);
figure
plot(t2,h);
l1=length(s);
l2=length(h);
l=l1+l2-1;
S=fft(s,l);
H=fft(h,l);
conv=ifft(S.*H);
figure
plot(conv,'r-');
y=conv(h,s);
figure
plot(y,'b');
the program gives me the error "Subscript indices must either be real positive integers or logicals" in the line "y=conv(h,s)"...but I don't understand why...I'm going mad, please help me!
2 Comments
Matt J
on 2 Feb 2014
In future, please highlight your code and apply the
formatting button, as I have just done for you now.
Answers (2)
Roger Stafford
on 2 Feb 2014
You have used the term 'conv' two ways, first as an array and second as the convolution function. In the second usage, matlab still thinks it is now an array, so the h and s are misinterpreted as indices. That is probably the source of your error message.
Lesson to be learned: you should never use the name of a matlab function as also the name of something else. It is "sacrosanct".
See Also
Categories
Find more on Get Started with MATLAB in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!