The function isreal not working?

function [calc_valid, EM] = input_check(N,t,S,EV)
inputs = [N,t,S,EV]; %The inputs are placed in a vector.
calc_valid = 0;
if 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~=0 && N<1 || N>8000 %This checks if N is not within the range 1:8000 or not = 0.
EM = 'ERROR: N is not within the range 1:8000';
elseif t~=0 && t<(1/8000) || t>2 %This checks if t is not within the range 1/8000:2 or not = 0.
EM = 'ERROR: t is not within the range 1/8000:2';
elseif S~=0 && S<25 || S>51200 %This checks if S is not within the range 25:51200 or not = 0.
EM = 'ERROR: S is not within the range 25:51200';
elseif EV<-6 || EV>23 %This checks if EV is not within the range -6:23.
EM = 'ERROR: EV is not within the range -6:23';
elseif N==0 && t==0 || N==0 && S==0 || t==0 && S==0
EM = 'ERROR: Only EV and one other variable are permitted to be zero';
else
EM = '';
calc_valid = 1;
end
end
For some reason all the other checks work except isreal ?

4 件のコメント

the cyclist
the cyclist 2014 年 5 月 21 日
It would be much easier to help you if you gave us one specific example of where the isreal() function is giving you a result different from what you expect.
dpb
dpb 2014 年 5 月 21 日
編集済み: dpb 2014 年 5 月 21 日
function [calc_valid, EM] = input_check(N,t,S,EV)
inputs = [N,t,S,EV]; %The inputs are placed in a vector.
...
Biggest problem I see is that unless all of the input arguments are present and consistent in class and dimension the concatenation is going to fail before you ever get to the if clauses.
Probably need to start w/ narginchk and then if it's deemed that important check the variety of each or put the concatenation statement in a try...catch block or somesuch to screen before the other more specific checks if needed.
Also, in the tests of the form of
elseif N~=0 && N<1 || N>8000
, I've a little utility function for such to save writing the test logic over and over that I call isbetween --
function flg=isbetween(x,lo,hi)
% returns T for values within range of input
% SYNTAX:
% [log] = isbetween(x,lo,hi)
% returns T for x between lo and hi values, exclusive
flg= (x>lo) & (x<hi);
I've another iswithin that is an inclusive test of the bounds.
In use the above would be
elseif N~=0 & isbetween(N,1,8000)
...
Yes, it's nothing but "syntactic sugar" but makes the upper level code easier to read (imo) and saves a little typing.
Roger Wohlwend
Roger Wohlwend 2014 年 5 月 22 日
There's nothing wrong with the isreal command. Are you sure that it is not working properly? Can you give as example (e.g. values for the input variables) where the command fails?
Giuseppe
Giuseppe 2014 年 5 月 27 日
Cheers, This helped alot.

サインインしてコメントする。

回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeData Type Identification についてさらに検索

製品

質問済み:

2014 年 5 月 21 日

コメント済み:

2014 年 5 月 27 日

Community Treasure Hunt

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

Start Hunting!

Translated by