Hi(adsbygoogle = window.adsbygoogle || []).push({});

I'm new to matlab and I'm trying to write a code that executes the same process under two separate conditions>

condition 1: that scalar value dE is less than or equal to zero.

condition 2: that scalar value r is less than or equal to scalar value w.

I'd like to same series of calculations to be executed ifeitherof these conditions are true (or both) like an OR statement.

I've tried to accomplish this using an if and elseif combination.

r=0

w=1

dE=0

L1=ones(N)

for i=1:t

if (dE<=0)

elseif (r<=w)

<program statements>

else

<final condition>

end

However, it does not seem to be working. Most examples of the elseif statement I've seen online has two separate series of commands for the if and elseif condition

e.g

if expression1

<program statements1>

elseif expression2

<program statements2>

end

Is it possible that my code will not work unless I write the if/elseif statements separate (i.e. copy and paste my current process)? If so, is there another method I could use or do I need to repeat my statements.

Thanks

**Physics Forums - The Fusion of Science and Community**

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

# Matlab: If/Elseif 2 conditions.

Loading...

Similar Threads - Matlab Elseif conditions | Date |
---|---|

How to program this in Matlab | Feb 28, 2018 |

Matlab Making a short test for self-adjointness | Feb 23, 2018 |

Matlab Plotting Coordinate Transformations in Matlab | Feb 12, 2018 |

Mathematica "Do" loop with "If" conditional | May 20, 2016 |

**Physics Forums - The Fusion of Science and Community**