From: Mohammad on
Hello,

I've have a function trail5(d,g,h) and I want either all the variables to be integers, or only one with the other to ending in .5. (I want d,g,h to increase in steps of .5, but I want to eliminate situations where the above isn't true.)

Thanks in advance!

Cordially, Mohammad
From: Matt Fig on
You could let the user know by putting an input argument checker which errors out:

if d~=floor(d) || g~=floor(g) || h~=floor(h)
error('Only integer inputs are allowed, try again.')
end


Alternatively, you could put the same IF evaluation at the start of the function, and instead of error-ing out just round the inputs using ROUND. If you do so, it is a good idea to issue a warning to the user to say this is being done.
From: Mohammad on
"Matt Fig" <spamanon(a)yahoo.com> wrote in message <hvdljv$65f$1(a)fred.mathworks.com>...
> You could let the user know by putting an input argument checker which errors out:
>
> if d~=floor(d) || g~=floor(g) || h~=floor(h)
> error('Only integer inputs are allowed, try again.')
> end
>
>
> Alternatively, you could put the same IF evaluation at the start of the function, and instead of error-ing out just round the inputs using ROUND. If you do so, it is a good idea to issue a warning to the user to say this is being done.

What if I want to try all values of d from 1:.5:some constant n and the same for g and h?

Is there some if clause like d+g+h=integer?

(BTW, thanks!)
From: Matt Fig on
Well, why not take what you have been shown and work with it a little?

V = d+g+h;
if V~=floor(V)
% Do what you need to do here.
end
From: Walter Roberson on
Matt Fig wrote:
> You could let the user know by putting an input argument checker which
> errors out:
>
> if d~=floor(d) || g~=floor(g) || h~=floor(h)
> error('Only integer inputs are allowed, try again.')
> end

Alternately,

if mod(d,1) || mod(g,1) || mod(h,1)
error('Only integer inputs are allowed, try again.')
> end