필터 지우기
필터 지우기

How to find percentage of Similarity between two logical matrices

조회 수: 2 (최근 30일)
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 CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by