Error with conv function. Using discrete functions but I keep getting an error.

Here's my Code
----
%f(n) = u(n) − u(n − 4);
x = -10:10;
y = (x >= 0) & (x < 4);
stem(x,y);
a_x = -10:10;
a=conv(y,y);
stem(a_x, a);
title('f(n) * f(n)');
-----
The error im getting is this ERROR;
Undefined function 'conv2' for input arguments of type 'char'.
Error in conv (line 40)
c = conv2(a(:),b(:),shape);
---
Also I'm running by section and line 40 is not within it. Plus when I comment out the conv function that I am calling the error disappears.

 Respuesta aceptada

David Goodmanson
David Goodmanson el 21 de Dic. de 2017
Editada: David Goodmanson el 21 de Dic. de 2017
Hi Jasmine,
This error does not occur in the latest version of Matlab, but if you have, for example, 2015a, the error is as you state.
The reason for the error is that y is a logical variable and conv is choking on that. If you convert to reals with
y = double((x >= 0) & (x < 4));
then the error goes away.
The reason you can't find line 40 is that conv2 is a function called by conv, and the call is contained in conv. If you do 'type conv' you can see what is going on. ('Edit conv' will show the line number, but it's not as safe to do that because it's possible to change conv and save it by mistake. 'Type conv' does not have that issue).

2 comentarios

I'm using 2016a and the error for some reason is persisting.
do you mean the error doesn't go away when you use the 'double' function?

Iniciar sesión para comentar.

Community Treasure Hunt

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

Start Hunting!

Translated by