MATLAB: How to creat condition

condition

For example, I want to calculate if 0<d<2, F=2*d if 2<d<3, F=5*d
I tried to figure it out but It is beyond my ability. Please help me

Best Answer

  • d=1;
    if and(d>0, d<2)
    F=2*d;
    elseif and(d>2, d<3)
    F=5*d;
    end
    You can also use "if d>0 && d<2" instead. Type "help relop" to learn about relational operators.