Error: Conversion to logical from sym is not possible.

2 views (last 30 days)
geometry geometry
geometry geometry on 19 Mar 2018
Commented: Walter Roberson on 19 Mar 2018
Why I get the error in title?
syms x h myconv
myconv=0;
h=0;
x(n)=(1/2^(-n+1))*(heaviside(n+2)-heaviside(n-2));
if (0<n)&&(n<7)
for i=-1000:1:n
h=h+(sin(2*i)+(-1)^i)*(heaviside(i+3)-heaviside(i-5));
end
else
h=0;
end
for i=-1000:1:1000
myconv=x(i)*h(n-i)+myconv;
end
N=-5:1:5;
figure
subplot(2,2,1);
stem(N, subs(x,n,N), 'bo');
title('x(n)')
subplot(2,2,2);
stem(N, subs(h,n,N), 'ro');
title('h(n)')
subplot(2,2,3);
stem(N, subs(myconv,n,N), 'ko');
title('convolution')
  5 Comments
Walter Roberson
Walter Roberson on 19 Mar 2018
"Error using : (line 38) Cannot compute the number of steps from -1000 to n by 1."
It is not permitted to have a symbolic variable as a bound for a for loop.

Sign in to comment.

Answers (0)

Community Treasure Hunt

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

Start Hunting!