Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Number of values greater than a threshold

I have a matrix A. Now I want to find the number of elements greater than 5 and their corresponding indices. How to solve this in matlab without using for loop?

For example if A = [1 4 6 8 9 5 6 8 9]':

  • Number of elements > 5: 6
  • Indices: [3 4 5 7 8 9]
like image 485
MKS Avatar asked Oct 05 '12 00:10

MKS


People also ask

How do you count values greater than a number in Python?

Use COUNTIF to figure cells greater than some chosen figure Now COUNTIF function will count the number of cells in the selected data range that contain a numeric value greater than the specified numeric value in criterion expression and will return the result as a number.

What Matlab command do you use to calculate the total number of entries larger than two?

allAreas = [S. Area];

How do I count variables in R?

count() lets you quickly count the unique values of one or more variables: df %>% count(a, b) is roughly equivalent to df %>% group_by(a, b) %>% summarise(n = n()) . count() is paired with tally() , a lower-level helper that is equivalent to df %>% summarise(n = n()) .

How do you count in Matlab?

A = count( str , pat ) returns the number of occurrences of pat in str . If pat is an array containing multiple patterns, then count returns the sum of the occurrences of all elements of pat in str . count matches elements of pat in order, from left to right.


1 Answers

You use find:

index = find(A>5);
numberOfElements = length(index);
like image 132
Jonas Avatar answered Sep 19 '22 16:09

Jonas