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:
Errors in plotting Unit Step Function and Ramp Function !!!!

Subject: Errors in plotting Unit Step Function and Ramp Function !!!!

From: Animesh Pandey

Date: 21 Jan, 2011 18:26:05

Message: 1 of 4

t = -10:0.1:10; % Unit Step Function
y(t>=0) = 1;
y(t<0) = 0;
plot(t,y)

%%

t = -2 :0.001: 2; % Unit Impulse.......
y(t==0) = 1;
y(t~=0) = 0;
plot(t,y)

%%

t = -2 : 0.001 : 2; %Ramp Function
y(t>=0) = t;
y(t<0) = 0;
plot(t,y)
%%

For the Unit Step I am getting an error
??? Error using ==> plot
Vectors must be the same lengths.

For the Impulse func. if I change 't = -2 : 0.001 : 2 ' .... to something other like
t = -10 :0.1 :10....

Please help me removing those errors !!!!

For the Ramp....
??? In an assignment A(:) = B, the number of elements in A and B
must be the same.

Subject: Errors in plotting Unit Step Function and Ramp Function !!!!

From: Paulo Silva

Date: 21 Jan, 2011 19:50:26

Message: 2 of 4

"Animesh Pandey" wrote in message <ihcj3t$9fn$1@fred.mathworks.com>...
> t = -10:0.1:10; % Unit Step Function
> y(t>=0) = 1;
> y(t<0) = 0;
> plot(t,y)
>
> %%
>
> t = -2 :0.001: 2; % Unit Impulse.......
> y(t==0) = 1;
> y(t~=0) = 0;
> plot(t,y)
>
> %%
>
> t = -2 : 0.001 : 2; %Ramp Function
> y(t>=0) = t;
> y(t<0) = 0;
> plot(t,y)
> %%
>
> For the Unit Step I am getting an error
> ??? Error using ==> plot
> Vectors must be the same lengths.
>
> For the Impulse func. if I change 't = -2 : 0.001 : 2 ' .... to something other like
> t = -10 :0.1 :10....
>
> Please help me removing those errors !!!!
>
> For the Ramp....
> ??? In an assignment A(:) = B, the number of elements in A and B
> must be the same.

the problem I think you have is that y was defined before and you didn't clear it, so it has a different length from t, your code only changes part of y, do this before assign values to y that way:

clear y %or clear or clear all, y=0 will also work, you must have length(y)<length(t)
%your code remains the same
t = -10:0.1:10; % Unit Step Function
y(t>=0) = 1;
y(t<0) = 0;
plot(t,y)

Subject: Errors in plotting Unit Step Function and Ramp Function !!!!

From: Paulo Silva

Date: 21 Jan, 2011 20:01:04

Message: 3 of 4

for the ramp you do the same like you did for the step but use t.*y instead of just y on the plot function :)

y=0;
t = -1 : 0.001 : 1; %Ramp Function
y(t>=0) = 1
y(t<0) = 0;
plot(t,t.*y)

Subject: Errors in plotting Unit Step Function and Ramp Function !!!!

From: RochelleVang30

Date: 25 Feb, 2011 16:43:01

Message: 4 of 4

freelance writer

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