How to find percentage of Similarity between two logical matrices

5 ビュー (過去 30 日間)
julian gaviria
julian gaviria 2023 年 1 月 25 日
コメント済み: julian gaviria 2023 年 1 月 25 日
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 件のコメント
the cyclist
the cyclist 2023 年 1 月 25 日
編集済み: the cyclist 2023 年 1 月 25 日
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?

サインインしてコメントする。

採用された回答

Image Analyst
Image Analyst 2023 年 1 月 25 日
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?

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

製品


リリース

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by