【问题标题】:How to find objects by specifying the range of property value?如何通过指定属性值的范围来查找对象?
【发布时间】:2018-03-03 09:43:51
【问题描述】:

在 Matlab 中我定义了一个类并创建了一堆对象,我如何通过指定某个属性的范围来选择所有对象的子集?

例如,如果我有一个 person 类,其属性为 name (char) 和 height (double),我如何在 x 和 y 之间找到所有 personheight

在这个example中,它使用findobj来查找具有char属性的对象与精确值匹配,比如

NW = findobj(PB,'Name','Nancy Wong');

但是对于数值和范围,我该怎么做呢?

【问题讨论】:

    标签: matlab sorting oop object properties


    【解决方案1】:

    您可以根据需要的条件手动创建一个逻辑向量,并用于选择对象:

    h = [PB.height]; % collect all height values in a vector
    ind = (x<=h) & (h<=y); % logical index of values in the desired range
    NW = PB(ind); % apply that index to select objects
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-09-19
      • 1970-01-01
      • 1970-01-01
      • 2013-07-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多