MATLAB: N as the natural numbers

\nnatural numbers

What command is used to enter that n is element of the natural numbers?

Best Answer

You might try something like this (if n is a scalar):
if n > 0 && floor(n) == n
% n is a natural number
else
% n is not a natural number
end
Or if n is a vector or matrix of numbers, you can see which ones are natural numbers like this:
is_natural = n > 0 & floor(n) == n;
And get just those elements of n that are natural numbers like this:
natural_n = n(is_natural);
Related Question