Вопрос

I'm trying to do a rather simple operation, which I somehow fail to successfully perform. What I have is an array (array0) of values, say 1000 of them, all between 0 and 10. Now what I want to do is create three separate arrays:

array1 = all elements of array0 that are equal to 3 or smaller array 2 = all elements from array0 that are larger than 3 but equal to or smaller than 7 array 3 = all elements from array0 that are larger than 7

Now, array1 and array3 work just fine. I use

array1= array0(array0<=3);
array3= array0(array0>7);

But array 2 is a problem. The 'logical' thing for me is to try

array2= array0(3<array0<=7);

But this doesn't work, it just gives me an empty array. It doesn't give an error though. Could anyone help me find the flaw in my code?

Это было полезно?

Решение

You need to use a logical "and" operator like this:

array2= array0(array0>3 & array0<=7);

similar to how you might say it in English, A is greater than 3 AND less than or equal to 7.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top