2010-10-26 57 views
0

我有一个任意值的行向量。我对如何获得小于阈值的所有列?

  • 其中包含一个值< =指定的阈值
  • 其位于低于阈值的列数的列的列编号。

在MATLAB中有没有比使用for -loop更好的计算方法?

回答

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

我很肯定这是重复的,但我的搜索功能今天很弱。

无论如何,你可以使用find这个

columnId = find(array<threshold) 
numberOfColumnsBelowThreshold = length(columnId) 
+0

同样给我,因此,我再次问它... :) – Etan 2010-10-26 18:22:59