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 (최근 30일)
이전 댓글 표시
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
댓글 수: 1
Roger Stafford
2016년 6월 15일
You will get a complex answer for that third case of log(5/2-3) since you are taking the logarithm of a negative number.
채택된 답변
KSSV
2016년 6월 15일
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.
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!