使用matlab过滤基于条件的数据 [英] Filtering of data based on condition using matlab

查看:181
本文介绍了使用matlab过滤基于条件的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有 ref 值作为

ref = [9.8 13 10.51 12.2 10.45 11.4]

值中as

and In values as

In = [10.7 11 11.5 11.9 12]

我想要做以下两件事:

I want to do following two things :


  1. 识别哪个值中最接近与 ref 值匹配的值,然后在
  2. 之后检查匹配的 In 的值低于或高于 ref 的值。如果它比在array1中保存的低,并且如果它比在array2中保存的更高的话。
  1. Identify which In value closest matches with ref value and then after
  2. To check whether the matched In value is lower or higher than ref value. If it is lower than saved in array1 and if it is higher than saved in array2


推荐答案

查看下面的代码片段作为许多解决方案之一:

See the following code snippet as one of many solutions:

% it would be a much better style 
% to initialize the result vectors here properly!
a1 = [];
a2 = [];

for i=1:length(P_in)
    [value, ind] = min(abs(P_in(i) - P_ref));

    if P_in(i) <= P_ref(ind)
        a1 = [a1 P_in(i)];
    else
        a2 = [a2 P_in(i)];
    end;
end;

与给定的向量

with the given vectors

P_ref = [9.8 13 10.51 12.2 10.45 11.4];
P_in = [10.5 11 11.5 11.9 12];

我得到以下结果:

I get the following result:

array1 = [10.5000   11.0000   11.9000   12.0000]
array2 = [11.5000]

这篇关于使用matlab过滤基于条件的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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