This example shows a MATLAB M-file for plotting step functions in three horizontal regions of the graphics window.
MATLAB M-File example3.m:
%
% M-File Name: example3.m
%
% Description: M-file to divide the graphics window into three
% horizontal regions and plot a step function in each.
%
clear % clear all variables from workspace
clf % clear figures
%****************************************************************************
% Create the first step function
t0 = -2.0:0.01:-0.01; % define u(t)=0, -2<=t<=-.01
u0 = zeros(size(t0));
t1 = 0:0.01:3; % define u(t)=1, 0<=t<=3
u1 = ones(size(t1));
t = [t0 t1]; % create t and u(t)
u = [u0 u1];
subplot(3,1,1) % divide graphics region into 3 rows and
% 1 column - put first plot in region 1
plot(t,u) % plot solid step function
grid % add grid and labels to plot
xlabel('t(s)')
ylabel('u(t)')
title('Step Function')
%****************************************************************************
% Create the second step function
t0 = -2.0:0.01:0.99; % define u(t-1)=0, -2<=t<=.99
u0 = zeros(size(t0));
t1 = 1.0:0.01:3; % define u(t-1)=1, 1<=t<=3
u1 = ones(size(t1));
t = [t0 t1]; % create t and u(t)
u = [u0 u1];
subplot(3,1,2) % divide graphics region into 3 rows and
% 1 column - put second plot in region 2
plot(t,u,'--') % plot dashed step function
grid % add grid and labels to plot
xlabel('t(s)')
ylabel('u(t-1)')
title('Step Function Shifted Right')
%****************************************************************************
% Create the third step function
t0 = -2.0:0.01:-1.01; % define u(t+1)=0, -2<=t<=-1.01
u0 = zeros(size(t0));
t1 = -1.0:0.01:3; % define u(t+1)=1, -1<=t<=3
u1 = ones(size(t1));
t = [t0 t1]; % create t and u(t)
u = [u0 u1];
subplot(3,1,3) % divide graphics region into 3 rows and
% 1 column - put third plot in region 3
plot(t,u,'-.') % plot dash-dot step function
grid % add grid and labels to plot
xlabel('t(s)')
ylabel('u(t+1)')
title('Step Function Shifted Left')
Run example3.m by Typing example3 at the prompt after
saving example3.m in your working directory.
MATLAB Plot Generated: