How to draw a discontinue function

Hi all, I have x(t) = cos(t) and y(t) = 0.5 if abs(x(t)) larger than 0.5, other wise y(t) = x (t). I have no idea how to plot y(t). Please help me!!!

 采纳的回答

t = 0:0.01:2*pi;
x = cos(t);
y = x;
y(abs(x)>0.5) = 0.5;
% to see the discontinuity
stem(t(1:400),y(1:400))
If you really want to see the discontinuity most clearly, it's probably a good idea to delete the baseline in the stem plot.
h = stem(t(150:250),y(150:250),'markerfacecolor',[0 0 1]);
axis tight;
delete(get(h,'baseline'))

2 个评论

Thank you for your answer. But I am not sure about your notation y(abs(x)>0.5) does that mean y is a function and abs(x)>0.5 is the argument? Can I say if abs(x)>0.5 y = 0.5 instead? Thanks!
that is logical indexing, it says for all the elements where the absolute value of x is greater than 0.5, set the corresponding y element to 0.5. That is the definition you gave. I think logical indexing is the easiest way to do it.

请先登录,再进行评论。

更多回答(0 个)

类别

帮助中心File Exchange 中查找有关 Vehicle Network Toolbox 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by