代码之家  ›  专栏  ›  技术社区  ›  Kris

检查行是否满足Matlab中的要求

  •  0
  • Kris  · 技术社区  · 7 年前

    我连续有这样的特征

    ...
    |  2  |  2.3  |  14  |  1050  |  6  |  500  |  300  |  1500  |
    ...
    

    我有上界和下界。如何检查我的行是否符合这些限制?

    3 回复  |  直到 7 年前
        1
  •  0
  •   Κωνσταντίνος Ατζαράκης    7 年前

    那怎么样?

    upper_bounds = rand(1, 10) %random upper bound
    lower_bounds = upper_bounds/5 %random lower bound    
    row = rand(1, 10) %random row
    % answer
    satisfied = (row < upper_bounds & row > lower_bounds)
    

    输出:

    upper_bounds =
    
        0.1067    0.9619    0.0046    0.7749    0.8173    0.8687    0.0844    0.3998    0.2599    0.8001
    
    
    lower_bounds =
    
        0.0213    0.1924    0.0009    0.1550    0.1635    0.1737    0.0169    0.0800    0.0520    0.1600
    
    
    row =
    
        0.4314    0.9106    0.1818    0.2638    0.1455    0.1361    0.8693    0.5797    0.5499    0.1450
    
    
    satisfied =
    
         0     1     0     1     0     0     0     0     0     0
    
        2
  •  1
  •   Farid Arbai    7 年前

    假设上界和下界分别存储在上界和下界中:

    satisfies_upper_bound = (max(features) < upper_bound);
    satisfies_lower_bound = (min(features) > lower_bound);
    is_acceptable = (satisfies_upper_bound & satisfies_lower_bound);
    

    希望有帮助!

        3
  •  0
  •   Kris    7 年前

    我发现了问题所在。我已经检查过了

    A <= lb & A >= ub
    

    我得到了8x8矩阵,这不是我需要的。我转换了lb和ub,最后得到了一个1x8(0 1)矩阵,它解决了我的问题。

    感谢大家的贡献!