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

 채택된 답변

Azzi Abdelmalek
Azzi Abdelmalek 2016년 3월 21일
편집: Azzi Abdelmalek 2016년 3월 21일

0 개 추천

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

Walter Roberson
Walter Roberson 2016년 3월 21일
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에 대해 자세히 알아보기

질문:

NT
2016년 3월 21일

댓글:

2016년 3월 21일

Community Treasure Hunt

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

Start Hunting!

Translated by