【问题标题】:How to remove NaN from MATLAB tables? [closed]如何从 MATLAB 表中删除 NaN? [关闭]
【发布时间】:2020-01-09 03:53:57
【问题描述】:

我在评估语义分割网络时得到NaN 值。如何将NaN 替换为0

metrics = 

  semanticSegmentationMetrics with properties:

              ConfusionMatrix: [9×9 table]
    NormalizedConfusionMatrix: [9×9 table]
               DataSetMetrics: [1×5 table]
                 ClassMetrics: [9×3 table]
                 ImageMetrics: [5×5 table]

 metrics.ClassMetrics

ans =

  9×3 table

                   Accuracy      IoU      MeanBFScore

                   ________    _______    ___________
    Fat                  0           0            0  
    Intestine          NaN           0          NaN

【问题讨论】:

    标签: matlab matrix nan matlab-table


    【解决方案1】:
    A = rand(4);  % Get random matrix
    A(A>0.9) = nan; % Set some points to NaN
    A
    A =
        0.0596    0.5216    0.7224       NaN
        0.6820    0.0967    0.1499    0.6490
        0.0424    0.8181    0.6596    0.8003
        0.0714    0.8175    0.5186    0.4538
    A(isnan(A)) = 0  % Get NaN values, set to 0
    A =
        0.0596    0.5216    0.7224         0
        0.6820    0.0967    0.1499    0.6490
        0.0424    0.8181    0.6596    0.8003
        0.0714    0.8175    0.5186    0.4538
    

    您可以使用isnan 执行此操作。这会创建一个逻辑掩码,您可以将 can use to index 恢复为原始掩码,并且可以将所有对应的元素设置为所需的数字(在本例中为 0)。

    对于tables ismissing 似乎是isnan 的可行替代方案;语法完全相同 (A(ismissing(A)) = 0)。

    【讨论】:

    • 嗨阿德里安,我该怎么办?
    • @Sohail 就是这样。由于您没有展示如何创建 semanticSegmentationMetrics 或其他任何内容,因此我无法更详细地告诉您。只需在任何内容上使用isnan()
    猜你喜欢
    • 2012-06-17
    • 1970-01-01
    • 2014-03-13
    • 1970-01-01
    • 2018-09-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-01-23
    相关资源
    最近更新 更多