-1

I am getting NaN values when I am evaluating a semantic segmentation network. How can I replace NaN with 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
Adriaan
  • 17,741
  • 7
  • 42
  • 75
Sohail
  • 21
  • 3

1 Answers1

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

You can do this using isnan. This creates a logical mask which you can use to index back into your original, and can set all corresponding elements to the desired number (0 in this case).

For tables ismissing seems to be a viable alternative to isnan; syntax is exactly the same (A(ismissing(A)) = 0).

Adriaan
  • 17,741
  • 7
  • 42
  • 75
  • Hi Adriaan, How can i do in my case? – Sohail Sep 06 '19 at 09:28
  • 1
    @Sohail like this, exactly. Since you don't show how you create your `semanticSegmentationMetrics` or whatever it is, I cannot tell you in more detail. Just use `isnan()` on whatever that is. – Adriaan Sep 06 '19 at 09:30