Trying to plot function
显示 更早的评论
Hey, so ihave been asked to plot this function

I found a way to do this
syms x
y=piecewise(x<-4, 0, -4<=x<3, x+2, x>=3, x-2);
fplot(y)
and i get this graph

Now, when i try another way to do this
i get this graph

this is the code
t = linspace(1,1000,1000); %%time
X1=@(t) (t<=-4).*0+(t>=-4 & t<3).*(t+2)+(t>=3).*(t-2);
subplot(2,2,1)
plot (t,X1(t))
axis([-6 6 -20 20]);
Im trying to understand why this way (the second graph) doesnt work.
Thnx.
4 个评论
Michael Van de Graaff
2021-4-1
well for one thing, in the second instance you are defining you x-coordinates as going from 1 to 1000, so no, you wont have anything plotted below x=1
Naor t
2021-4-1
Michael Van de Graaff
2021-4-1
also, i'm confused, can you tell me which point on you plot is incorrect?
are you aware that you are plotting only integer X values and the line is just connecting the dot's
Michael Van de Graaff
2021-4-1
Oh, you need
t = linspace(-6,6,1000);
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Mathematics 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
