Why TIME SHIFTING is not happening? (Thank you in advance!)

1 次查看(过去 30 天)
As you can see, I am defining the value to be 1 after n = 1, t=1.
But if you look at the output, it is still starting from 0 in both cases.
The code is as follows-
close all
a = 0;
a1 = a + 1;
n1 = -5;
n2 = 5;
n = n1:n2;
x1(n>=a1) = 1;
stem(n,x1);
title('Unit Step Signal - Discrete')
xlabel('t')
ylabel('ust')
axis([-5 5 0 2])
grid on
n3 = 5;
t = 0:n3;
x2(t>=a1) = 1;
plot(t,x2)
title('Unit Step Signal - Continuous')
xlabel('t')
ylabel('ust')
axis([-5 5 0 2])
grid on
Screenshot (36).png

回答(2 个)

the cyclist
the cyclist 2019-9-30
Both of the plots show exactly what I would expect from your code.
Which plot do you think is incorrect -- the discrete, or the continuous?
Making a guess at the solution:
In your continuous plot, you are drawing a connecting line between each plotted data point. So, you have a connecting line from (t==0, x2==0) to (t==1,x2==1). There are no data points in between, so it looks like there is a gradual increase, where there is not.
If instead of
t = 0:n3;
you use
t = 0:0.01:n3;
then you will have something more akin to a continuum of points, and the jump will happen between 0.99 and 1. Maybe this is closer to what you expected?

Steven Lord
Steven Lord 2019-9-30
Instead of using plot for your continuous plot, I think you want to use a stairs plot.
figure
a = 0;
a1 = a + 1;
n3 = 5;
t = 0:n3;
x2(t>=a1) = 1;
stairs(t,x2) % Instead of plot
title('Unit Step Signal - Continuous')
xlabel('t')
ylabel('ust')
axis([-5 5 0 2])
grid on
In the Plots gallery (the Plots tab on the Toolstrip) one of the categories is named "MATLAB STEM AND STAIR PLOTS", so they're in some sense related.

类别

Help CenterFile Exchange 中查找有关 2-D and 3-D Plots 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by