本文介绍了MATLAB:选择所有的数组除了在给定范围的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在不属于特定范围内的数组的内容进行度量。

I'd like to perform metrics on the contents of an array that do NOT fall within certain ranges.

例如,我有1000行2列的数组。我想在一列上的所有元素进行平均值()计算(假设列#2)不属于行50-150,250-300,400-700 900-950和

For example, I have an array with 1000 rows and 2 columns. I'd like to perform a mean() calculation on all the elements in one column (let's say column #2) that don't fall in rows 50-150, 250-300, 400-700 and 900-950.

因此​​,平均应该根据行数1-49,151-249,301-399,701-899和951-1000来计算

Thus, the mean should be calculated based on rows 1-49, 151-249, 301-399, 701-899 and 951-1000.

任何想法如何去了解呢?

Any ideas how to go about this?

编辑:我要指出,这是包括这些项目将在每次程序运行时改变。因此,我不能就这么硬code的夹杂物;他们需要的基础上,排除待解决。

I should point out that those items which are included will change each time the program is run. Therefore, I can't just hard-code the inclusions in; they need to be worked out based on the exclusions.

推荐答案

如何

M = rand(1000,2);
idx = setdiff(1:size(M,1), [50:150, 250:300, 400:700, 900:950]);

MM = M(idx,:)

现在适用任何功能,过滤的矩阵:

Now apply any function to the filtered matrix:

mean(MM,1)

这篇关于MATLAB:选择所有的数组除了在给定范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 12:54