MATLAB: If statement element-by-element for vector of arbitrary size

element ifif statement

I need to emulate this VBA code in Matlab:
If M > 1 Then
PR_NS = (kp * M ^ 2 / (km * M ^ 2 + 2)) ^ e1 _
* (kp / (2 * k * M ^ 2 - km)) ^ e2
Else
PR_NS = 1
End If
Where M is a column vector of arbitrary (unknown) size and other items (kp, km, e1, e2) are scalers.
The intent is to return a column vector PR_NS of the same size as M. Depending on each value of M, each value of PR_NS may either be 1 or the value resulting from the equation.
I know this is a very basic question, but I am a newbie and have an urgent need to implement this. Thanks!

Best Answer

Thanks! Very nice.