views:

14

answers:

2

I have a row-vector with arbitrary values. I am interested in

  • the column IDs of the columns which contain a value <= a specified threshold
  • the number of columns which lie below the threshold.

Is there a more elegant way to compute this in MATLAB than using a for-loop?

+1  A: 

I'm fairly sure this is a duplicate, but my search-fu is weak today.

Anyway, you can use find for this

columnId = find(array<threshold)
numberOfColumnsBelowThreshold = length(columnId)
Jonas
same to me, therefore I have asked it again... :)
Etan
+2  A: 
>> thresh = 9;
>> x = randi(20, [1 10])
x =
    17    19     3    19    13     2     6    11    20    20
>> xBelowInd = find(x <= thresh)
xBelowInd =
     3     6     7
>> num = length(xBelowInd)
num =
     3
>> x(xBelowInd)
ans =
     3     2     6
Amro

related questions