Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Help in plotting a square wave using Syms

Subject: Help in plotting a square wave using Syms

From: Animesh Pandey

Date: 26 Feb, 2011 15:30:22

Message: 1 of 3

syms t
f = @(t) heaviside(t+0.5)-heaviside(t-0.5);
hold on
for n = -10 : 1 : 11;
    e = (-1)^n;
    ezplot(e*f(t-n));
end
hold off
grid on
ylim([-3,3]),xlim([-10,10]);

I do not get a correct plot using this !!!
Please suggest changes !!!
Thanks !!

Subject: Help in plotting a square wave using Syms

From: Nasser M. Abbasi

Date: 26 Feb, 2011 15:40:07

Message: 2 of 3

On 2/26/2011 7:30 AM, Animesh Pandey wrote:
> syms t
> f = @(t) heaviside(t+0.5)-heaviside(t-0.5);
> hold on
> for n = -10 : 1 : 11;
> e = (-1)^n;
> ezplot(e*f(t-n));
> end
> hold off
> grid on
> ylim([-3,3]),xlim([-10,10]);
>
> I do not get a correct plot using this !!!
> Please suggest changes !!!
> Thanks !!


ezplot( heaviside(t+0.5)-heaviside(t-0.5),[-1 1])

--Nasser

Subject: Help in plotting a square wave using Syms

From: Animesh Pandey

Date: 27 Feb, 2011 14:34:19

Message: 3 of 3

syms t
f = @(t) heaviside(t+0.5)-heaviside(t-0.5);
hold on
for n = -10 : 1 : 11;
    e = (-1)^n;
    ezplot(e*f(t-(n)), [-10,10]);
end
hold off
grid on
ylim([-3,3]),xlim([-10,10]);

The plot was better ... but there is a blue line on the x axis that is under every square wave, which should not be there !!! It was not looking like a wave but like many rect(t)'s on a long line !!!!
Please help !!
thnx

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us