0
$\begingroup$

I am trying to plot the following function:
enter image description here
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

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

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-')

Door/impulse function

$\endgroup$
0
$\begingroup$

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 :

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.