How do i show value that meets specific criteria in wolfram mathematica?

66 Views Asked by At

i will try to explain my problem Lets say i have data like this x={1,2,3,4,5,6} and my condition is 4<=x<=6 and I want to show that the value that meets criteria is 5. my program looks like this

k = 0;

Do[If[4 <= x[[i]] <= 6, k = k + 1], {i, 1, Length[data]}];

Print["amount of numbers that meets criteria ", k]

And my problem is that I don't know how to continue to show the Value of number that meets criteria.

1

There are 1 best solutions below

0
On BEST ANSWER

If you want to choose items that satisfy a condition then Select is often useful. If you want to know how many items satisfied the criteria then Length is often useful.

x = {1, 2, 3, 4, 5, 6};
Length[Select[x, 4<=#<=6&]]

gives you 3. That # and & notation is defining a function that has no name but that you can still use. You can get some information about how to use that by looking up Function in the help pages.