MATLAB Answers

how do i plot til some x one function and then other

1 view (last 30 days)
i want to plot plz help
y = { x x<=12
12 x>12 }


Sign in to comment.

Accepted Answer

Stephen Cobeldick
Stephen Cobeldick on 22 Oct 2020
Edited: Stephen Cobeldick on 22 Oct 2020
x = 0:0.1:20;
y = min(12,x);
In a more general case, use logical indexing, e.g.:
x = 0:0.1:20;
y = x;
y(y>12) = 12;

More Answers (0)


Community Treasure Hunt

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

Start Hunting!