Trouble giving decimal input

조회 수: 3 (최근 30일)
MD JAHIDUL HAQUE KHAN
MD JAHIDUL HAQUE KHAN 2020년 9월 23일
댓글: Walter Roberson 2020년 9월 23일
Hi, my code is as shown below, i tried as switch function instead of else if statement. However, the code is taking only integer numbers, for decimal numbers showing 'out of range'.
function category = pH21Category(pH)
switch true
case any(pH == 0:2)
category = 'Strongly acidic';
case any(pH == 3:5)
category = 'Weakly acidic';
case ismember(pH,6:8)
category='Neutral';
case ismember(pH,9:11)
category='Weakly Basic';
case ismember(pH,12:14)
category=('Strongly basic');
otherwise
category=('out of range');
end

채택된 답변

Walter Roberson
Walter Roberson 2020년 9월 23일
0:2 does not express the range starting from 0 and ending at 2.
0:2 expresses a vector of numbers starting from 0 and incrementing by 1 until 2 is reached. That is the vector containing 0, 1, and 2. No other values are included in 0:2
You will need to test
0<=ph & ph < 2
but think about whether you want < or <= for the bounds.
  댓글 수: 1
Walter Roberson
Walter Roberson 2020년 9월 23일
https://www.thoughtco.com/is-a-negative-ph-possible-603653

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 App Building에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by