How to find percentage of Similarity between two logical matrices

1 visualizzazione (ultimi 30 giorni)
The following code calculates the percentage of similarity between the attached logical matrices "c1" and "c2":
row = 168;
col = 390;
% Counting equal elements
equal = c1==c2;
% Number of equal elements
equalCount = sum(equal(:));
similarityPercentage= (equalCount / (row * col) ) * 100;
% Display similarityPercentage
disp(similarityPercentage);
How can I compare the same percentage of similarity only considering the matrix places with "1" values. To note, it's not about counting the number of ones. The aim is to see in which percentage the "1" values appear in both metrices in terms of their number (i.e., quantity) and their position in the respective matrices (i.e., row and col).
P.D., I also calculate the mse values for cross validation.
mse_val=mse(c1,c2);
Many thanks in advance
  1 Commento
the cyclist
the cyclist il 25 Gen 2023
Modificato: the cyclist il 25 Gen 2023
FYI, you can do your original calculation with this one-liner:
similarityPercentage = mean(c1==c2,"all")*100
I don't completely understand your question, though. Maybe you could use a smaller example, like
c1 = [1 1 1;
0 1 1;
0 0 1];
c2 = [1 0 0;
1 1 0;
1 1 0];
and tell us exactly what you expect the output to be?

Accedi per commentare.

Risposta accettata

Image Analyst
Image Analyst il 25 Gen 2023
Wouldn't it just be
row = 168;
col = 390;
% Counting equal elements
equal = c1==c2;
% Number of equal elements
equalCount = sum(equal(:));
% Count the number of 1's total
oneCount = sum(c1 | c2, 'all')
% Compute the percentage of both having 1 as a fraction of either having 1.
similarityPercentage = (equalCount / oneCount) * 100;
% Display similarityPercentage
disp(similarityPercentage);
or am I missing something?

Più risposte (0)

Prodotti


Release

R2022b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by