开发者

How to get all columns smaller than a threshold?

I have a ro开发者_运维百科w-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?


>> 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


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)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜