count elements falling within certain thresholds in array in matlab?

后端 未结 6 1651
无人及你
无人及你 2021-01-28 07:56

I have a huge vector. I have to count values falling within certain ranges. the ranges are like 0-10, 10-20 etc. I have to count the number of values which fall in certain rang

6条回答
  •  一生所求
    2021-01-28 08:42

    to count the values in a specific range you can use ismember,

    if m1 is vector use,

    k = sum(ismember(m1,0:10));
    

    If m1 is matrix use k = sum(sum(ismember(m1,0:10)));

    for example,

    m1=randi(20,[5 5])
    
     9    10     6    10    16
     8     9    14    20     6
    16    13    14     7    11
    16    15     4    12    14
     4    16     3     5    18
    
    sum(sum(ismember(m1,1:10)))
    
    12
    

提交回复
热议问题