How to determine if the input is a scalar real number

Some times it is interesting to know whether the input is a scalar real number, as for example if we are trying to introduce the sampling frequency of a sequence. We can use some of the following commands:

isscalar:   determine whether input is scalar (true=1 or false=0).
isnumeric:   determine whether input is a number (true=1 or false=0).
isreal:   determine whether input is a real number (true=1 or false=0).
isinf:   determine whether input is finite (true=1 or false=0).

Thus, if you want to be (absolutely) sure that your variable is a real scalar number (such a valid sampling frequency) you can write

if  isscalar(Fs) && isnumeric(Fs) && isreal(Fs) && ~isinf(Fs)
     disp(‘Sampling frequency is a valid number’)
end

Advertisements
This entry was posted in arrays, checking format, data format and tagged , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s