How to plot graph constant in Matlab?

13 views (last 30 days)
If I want plot graph same picture ,How to write code.

Accepted Answer

Walter Roberson
Walter Roberson on 20 Jun 2015
function r = Y(x)
r = zeros(size(x));
r(x<5) = -10;
r(x>10) = 15;
end
but now you need to decide what value you want to return if x is exactly 5 or exactly 10. Or at least you do if you want to do this in terms of a function.
If you just need it as a graph and not as a function, then let lowx be the lowest x to plot from, and highx to be the highest x to plot to, and then
plot([lowx 5 5 10 10 highx], [-15 -15 0 0 10 10]);
  1 Comment
Fieldza Field
Fieldza Field on 20 Jun 2015
Thank you Walter Roberson.I am beginer. I copy code and paste in matlab, but program is error function r = Y(x) | Error: Function definitions are not permitted in this context. How I should ? I'm Sorry,I'm not good english language.

Sign in to comment.

More Answers (0)

Categories

Find more on 2-D and 3-D Plots in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!