필터 지우기
필터 지우기

how to check if numbers in the vector is within range of 1:10

조회 수: 139 (최근 30일)
GOENG
GOENG 2015년 4월 16일
편집: Jan 2015년 4월 16일
while length(x) == 6
if x < -36 && x > 47
If there was an input and I had to check if the values of the array is within the elements of 1:10, how can i do it?
I though just checking if the input of array was bigger or small than the limited number it works but it didn't.
I'm assuming you have to check either all at once or one by one.
could someone help me?
Thank you in advance =]

답변 (2개)

Thorsten
Thorsten 2015년 4월 16일
all(x >= 1 & x <= 10)
  댓글 수: 2
GOENG
GOENG 2015년 4월 16일
I got an error for this
if all(inPut > -36 && inPut < 46)
disp('Do it again, within -36 to 46, and size of 1 by 6: ');
inPut = input('Please put a number within -36 to 46: ');
else
error message: Operands to the and && operators must be convertible to logical scalar values.
i put in the vector of inPut = [55 55 55 55 55 44] so one of the number is within range and the other 5 isn't to check.
James Tursa
James Tursa 2015년 4월 16일
Thorsten used a single &, and you used a double &&. The single & is element-wise operator and the double && is intended for scalar operands only. Use a single &.

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


Jan
Jan 2015년 4월 16일
편집: Jan 2015년 4월 16일
If the inputs are large, the creation of the temporary arrays consumes a lot of time. Then this MEX function is more efficient: FEX: anyExceed :
if anyExceed(x, 1, 10)
This avoids creating the temporary arrays t1 = x >=1 , t2 = x<=10 and t1&t2 and the code stops at the first matching element.
  댓글 수: 1
GOENG
GOENG 2015년 4월 16일
unfortunately it has to be something built in only. No external files but thanks for the link, that really does make it simpler.

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

카테고리

Help CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by