MATLAB: Multiple <,=,> in an if statement

multiple less than / greater than statements in an if statement

I have the following:
if i > m_1(1,1)& <= m_2(1,1)
w(i,1) = w_2
end
Which doesn't want to execute as it is an unexpected MatLab operator.
Is it due to syntax or do you have to specify domains in another way?

Best Answer

You have to make the comparisons independent relations:
if i > m_1(1,1) & i <= m_2(1,1)
w(i,1) = w_2
end
So in the first one, it compares ‘i’ to ‘m_(1,1)’, and in the second it makes an independent comparison of ‘i’ with ‘m_2(1,1)’.
Related Question