我在评估语义分割网络时得到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
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
.这将创建一个逻辑掩码,您可以使用该掩码索引回原始元素,并且可以将所有相应的元素设置为所需的数字(在本例中为0
(。
因为tables
ismissing
似乎是isnan
的可行替代方案;语法完全相同(A(ismissing(A)) = 0
(。