MATLAB: How do i plot til some x one function and then other

ploting

i want to plot plz help
y = { x x<=12
12 x>12 }

Best Answer

  • x = 0:0.1:20;
    y = min(12,x);
    plot(x,y,'-+')
    In a more general case, use logical indexing, e.g.:
    x = 0:0.1:20;
    y = x;
    y(y>12) = 12;