Question

I have a small problem in coding confusion 3x3 matrix by using matlab...

I tried the code below,

average = sum(diag(Mconf)./sum(Mconf,2))/3;

However, it get NaN for the confusion matrix is [0 0 0;1 2 3;4 5 6] or [1 2 3;0 0 0;4 5 6] or [1 2 3;4 5 6;0 0 0]

Was it helpful?

Solution

Try

average = sum(diag(Mconf)./sum(Mconf+eps,2))/3;

To eliminate the division by zero.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top