算上元素落入某些阈值内阵列中的MATLAB? [英] count elements falling within certain thresholds in array in matlab?

查看:138
本文介绍了算上元素落入某些阈值内阵列中的MATLAB?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个巨大的载体。我都数不过来下降在一定范围内的值。
的范围是一样0-10,10-20等我不得不计数落入一定的范围内的值的数目。

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

我做了这样的事情:

for i=1:numel(m1)
if (0<m1(i)<=10)==1
k=k+1;
end
end

还有:

if not(isnan(m1))==1
x=(0<m1<=10);
end

不过,这两个时间它给数组,它包含全1。有什么错我在干嘛?

But both the times it gives array which contains all 1s. What wrong am I doing?

推荐答案

您可以做这样的事情(也适用于非整数)

You can do something like this (also works for non integers)

k = sum(m1>0 & m1<=10)

这篇关于算上元素落入某些阈值内阵列中的MATLAB?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆