Matlab confirm is input is not an array

Confirm that the input is a positive integer and not an array. I got this far, but when I type in [1 2 3] is does not prompt to enter in the positive integer again.
n = input('Enter in a positive integer: ')
while (n<0) & (isvector(n))
n = input('Enter in a positive integer: ')
end

 采纳的回答

n = input('Enter in a positive integer: ')
while n<0 | numel(n)>1 | fix(n)~=n
n = input('Enter in a positive integer: ')
end

1 个评论

Test the number of elements first. "n<0" is false if you have a vector that contains a mix of negative and non-negative values.

请先登录,再进行评论。

更多回答(0 个)

类别

帮助中心File Exchange 中查找有关 Matrix Indexing 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by