# Plotting impulse functions on the same time axis with other functions in MATLAB

I am trying to plot the following function: I have to plot another function along with it all on the same plot. Got the other function working, but I can't seem to get this one working. The code below is my attempt at plotting the function:

t = 0:1:10;

for t=>1 && t<=1

n = 0:1;

end

plot(t,n)


Need help

• that's not a signal processing question, but a Matlab plotting question. – Marcus Müller Oct 13 at 11:39

The use of logical operators is not correct. A more generic verison is:

timeStart = -3; timeStop = 2; nSample = 1000;
time = linspace(timeStart,timeStop,nSample);
timeUp = 0; timeDown = 1;
data = zeros(size(time));
data((time>=timeUp) & (time<=timeDown)) = 1;
plot(time,data,'x-') Without knowing the other function it won't be useful to put an answer, but at least the following code plots the single pulse you have defined:

N = 1000;                   % number of points
Ti = 2;                     % time interval t in [-L,L]
t = linspace(-Ti,Ti,1000);  % the samped time "t"

pxv = zeros(1,N);           % pulse function vector x(t)

indt = (t >= 0) & (t <= 1);      % select time index for 0 <= t <= 1
pxv( indt ) = t( indt) ;    % define x(t) = t  , in 0<=t<=1

figure,plot(t,pxv);         % PLOT : Note that "t" and "pxv" MUST have same number of samples.
title('function x(t) = t  ,  for 0 \leq t \leq 1');
xlabel(' time t [s]');


The code results in the following plot : 