How to produce an 'if else' loop with an x starting at 1 and increasing to 3 by 1 at each end of the loop

2 views (last 30 days)
x = [1:1:3];
if x == 2; f2 = inf elseif x > 2; f2 = NaN else f2 = log(5/2-x) end
I'm trying to input a value of x = 1, then x = 2, then x = 3 to get three different answers

Accepted Answer

KSSV
KSSV on 15 Jun 2016
if x == 1;
f2 = inf
elseif x == 2;
f2 = NaN
elseif x ==3
f2 = log(5/2-x)
end
As Roger Stafford said, third case will be complex.

More Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!