How to verify input only contains certain numbers?

조회 수: 2 (최근 30일)
Ibro Tutic
Ibro Tutic 2017년 7월 12일
편집: Ibro Tutic 2017년 7월 12일
Lets say that users are required to enter the numbers: 35, 36, 37 in some order (b={'35', '36', '37'}). How would I go about verifying that these numbers were entered and not some other numbers and that each number was only entered once? So if the user entered 30,36,37 or 36,36,37 the program would error. The only acceptable input would be one where 35, 36, and 37 occur only once, in any order. Any ideas?

채택된 답변

per isakson
per isakson 2017년 7월 12일
편집: per isakson 2017년 7월 12일
An idea
>> b={'37', '36', '35'};
>> all( strcmp( unique( b ), {'35','36','37'} ) )
ans =
1
However, you have to check that length(unique(b))==3 before applying strcmp
  댓글 수: 2
Ibro Tutic
Ibro Tutic 2017년 7월 12일
Perfect, thanks!
Ibro Tutic
Ibro Tutic 2017년 7월 12일
편집: Ibro Tutic 2017년 7월 12일
Now I'm having some issues. I have two cell arrays, 'runs' and 'z7prtests'.
runs = {'27' '28' '108' '109'};
z7prtests = {'27' '28' '108' '109'};
all( strcmp( unique( runs ), z7prtests ) )
ans =
0
This doesn't seem to be working, any ideas?

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Troubleshooting in Polyspace Products for Ada에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by