如何根据 MA​​TLAB 中的某些条件将值添加到 table 的最后一列?

How to add values to last column of a table based on certain conditions in MATLAB?

我有一个 29736 x 6 table,简称 table_fault_test_data。它有 6 列,名称分别为 wind_direction、wind_speed、air_temperature、air_pressure、density_hubheight 和 Fault_Condition。我想要做的是用 1 或 0 值标记 Fault_Condition(最后一个 table 列中的数据,具体取决于其他列中的值。

我想做以下检查(例如)

  1. 如果 wind_direction 值 (column_1) 低于 0.0040 且高于 359.9940,则将对应于 table 的相应行的第 6 列条目标记为 1,否则标记为0.
  2. 对整个 table 执行此操作。同样,为其他人做这个检查 如 air_temperature、air_pressure 等。我知道如果-否则 将用于这些检查。但是,我真的很困惑我如何 可以对整个 table 做这个,然后将相应的值添加到 第 6 列(可能使用循环或其他东西)。

这方面的任何帮助 将不胜感激。非常感谢!

编辑: 进一步说明:我有一个名为 table_fault_test_data 的 29736 x 6 table 。我想根据以下条件将值添加到 table 的第 6 列:-

for i = 1:29736 % Iterating over the whole table row by row
    if(1st column value <x  | 1st column value > y)
         % Add 0 to the Corresponding element of 6 th column i.e. table_fault_test_data(i,6)
    elseif (2nd column value <x  | 2nd column value > y)
         % Add 0 to the Corresponding element of 6 th column i.e. table_fault_test_data(i,6)
    elseif ... do this for other cases as well
    else
         % Add 1 to the Corresponding element of 6 th column i.e. table_fault_test_data(i,6)

这就是我的要求的本质。我希望这有助于更好地理解问题。

您可以使用逻辑索引,table 也支持逻辑索引(如果可能,应避免循环)。例如,假设你要实现第一个条件,同时假设你的 x 和 y 是已知的;另外,让我们假设您的 table 被称为 t

logicalIndecesFirstCondition = t{:,1} < x | t{:,2} >y

然后您可以引用使用逻辑索引验证此条件的行(请参阅logical indexing

例如:

t{logicalIndecesFirstCondition  , 6} = t{logicalIndecesFirstCondition  , 6} + 1.0; 

对于逻辑条件为真的行,这会将 1.0 添加到第 6 列