where when x<0 y=100, when x is between 0 and 50 y=2(x+200), when x is between 50 and 100 y= (3x-(x/20)+10) and when x is over 100 y=299 in matlab

You can use conditional if statements and mathematical expressions to achieve this task in MATLAB.

main.m
x = % assign a value to variable x

if x < 0
    y = 100;
elseif x >= 0 && x <= 50
    y = 2*(x+200);
elseif x > 50 && x <= 100
    y = 3*x - (x/20) + 10;
else
    y = 299;
end
177 chars
12 lines

The above code block checks the value of variable x against different conditions using if-elseif-else statements. Depending on the value of x, a specific mathematical expression is used to calculate the value of y.

gistlibby LogSnag