how to check if numbers in the vector is within range of 1:10
194 次查看(过去 30 天)
显示 更早的评论
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 =]
0 个评论
回答(2 个)
Thorsten
2015-4-16
all(x >= 1 & x <= 10)
2 个评论
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
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.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!