필터 지우기
필터 지우기

Checking variables are valid for a set of conditions.

조회 수: 2 (최근 30일)
Giuseppe
Giuseppe 2014년 5월 21일
댓글: Giuseppe 2014년 5월 21일
The aim of this sub function is to determine if the inputs of a parent function are valid. The goal is that EM is a string displaying the relevant error if there is one. However something is not right? Maybe there is a more efficient way of doing so.?
function EM = EV(N,t,S,EV)
inputs = [N,t,S,EV]; %The inputs are placed in a vector.
if sum(inputs(:)==0)>2 %This checks if there is more than two zeros.
EM = 'ERROR: There is more than two zeros.';
elseif isreal(inputs)==0 && isa(inputs,'numeric')==0 %This checks if other than real numbers and numbers are inputted.
EM = 'ERROR: The inputs are not real numbers.';
elseif N<1 && N>8000 %This checks if N is not within the range 1:8000
EM = 'ERROR: N is not within the range 1:8000';
elseif t<(1/8000) && t>2 %This checks if t is not within the range 1/8000:2
EM = 'ERROR: t is not within the range 1/8000:2';
elseif S<25 && S>51200 %This checks S is within the range 25:51200
EM = 'ERROR: S is not within the range 25:51200';
elseif EV<-6 && EV>23 %This checks EV is within the range -6:23
EM = 'ERROR: EV is not within the range -6:23';
else
EM = 'There are no errors with the inputs.';
end
end

채택된 답변

Henric Rydén
Henric Rydén 2014년 5월 21일
편집: Henric Rydén 2014년 5월 21일
You have got AND mixed up with OR . N<1 AND N>8000 can never be true. You should use OR instead. OR is |
  댓글 수: 3
Sara
Sara 2014년 5월 21일
To be in the range then N > 1 && N < 8000 not the other way around!
Giuseppe
Giuseppe 2014년 5월 21일
Don't worry I have sorted this mess all out.

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

추가 답변 (0개)

카테고리

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

제품

Community Treasure Hunt

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

Start Hunting!

Translated by