How to find a unique indicator of a specific matrix?
1 view (last 30 days)
Show older comments
Can we find a unique indicator of a specific matrix?
for example, if there is the following matrix (generated by a specific case) , how can I find one indicator of it?
I tried to take the sumation of the absolute values of the Matrix, but it didnt work because it was similer or too close for other cases
M1 and M2 is the range that can the matrix M varies between them, they are generated from a one case but with a little variation in some parameters (I want to find indicator for each other and compare it with other cases)
in this case the indicator should be too close for these two matrices (they are generated from the same case)
M1 = [-0.321306015516281 -0.274347013364667 -0.244382392248534 -0.288238228952784;
0.0558620817276004 0.372558615192237 0.572777978587165 0.503058540034827;
0.879663610530521 -0.136530080441011 -0.146669343761813 -0.155051653631985;
-0.176098379345313 0.737213426291489 -0.317456953062300 -0.314726433029229;
-0.211259054671114 -0.342511568755319 0.574666860881602 -0.415568275258076;
-0.210220781888802 -0.326336514970413 -0.399587060803839 0.606679564783506]
M2 = [-0.329410894346382 -0.282164376523392 -0.250593904107229 -0.300770395163912;
0.0391745398039566 0.367487954611743 0.578801050109399 0.490318907952166;
0.880000126456464 -0.133241897165618 -0.141354513303187 -0.151019721814831;
-0.173510462331790 0.738010210780251 -0.318373231341420 -0.312738411276027;
-0.207557875879909 -0.344447577135199 0.568108475231932 -0.416369292422166;
-0.205833532679448 -0.322922994018591 -0.397620657310764 0.612493983612021]
4 Comments
Answers (2)
Walter Roberson
on 8 Feb 2023
https://www.mathworks.com/matlabcentral/fileexchange/31272-datahash but see https://stackoverflow.com/questions/48667340/matlab-fast-hash-of-a-matrix for faster Java based code.
3 Comments
Walter Roberson
on 8 Feb 2023
No. All cases involving summarizing multiple values as a single value are mathematically classed as "hashing". Some hashing methods are better for particular purposes than other methods are, but all deterministic functions
are classified as hash functions.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1289685/image.png)
dpb
on 8 Feb 2023
Moved: dpb
on 8 Feb 2023
M1 = [-0.321306015516281 -0.274347013364667 -0.244382392248534 -0.288238228952784;
0.0558620817276004 0.372558615192237 0.572777978587165 0.503058540034827;
0.879663610530521 -0.136530080441011 -0.146669343761813 -0.155051653631985;
-0.176098379345313 0.737213426291489 -0.317456953062300 -0.314726433029229;
-0.211259054671114 -0.342511568755319 0.574666860881602 -0.415568275258076;
-0.210220781888802 -0.326336514970413 -0.399587060803839 0.606679564783506];
M2 = [-0.329410894346382 -0.282164376523392 -0.250593904107229 -0.300770395163912;
0.0391745398039566 0.367487954611743 0.578801050109399 0.490318907952166;
0.880000126456464 -0.133241897165618 -0.141354513303187 -0.151019721814831;
-0.173510462331790 0.738010210780251 -0.318373231341420 -0.312738411276027;
-0.207557875879909 -0.344447577135199 0.568108475231932 -0.416369292422166;
-0.205833532679448 -0.322922994018591 -0.397620657310764 0.612493983612021];
100*(M2-M1)./M1 % percentage difference
tol0=1E-4; % set initial tolerance tightly...
N=numel(M1); % check for when all are outside tol
i=1;
t{i,1}=tol0;
n{i,1}=sum(ismembertol(M1,M2,t{i}),'all');
while n{i}<N
i=i+1;
t{i}=2*t{i-1};
n{i}=sum(ismembertol(M1,M2,t{i}),'all');
if i>10, break, end
end
semilogx(cell2mat(t),cell2mat(n),'x-','linewidth',1.5)
grid
You can 'spearmint with alternatives on max points or all or whatever suits....
We have no basis for any idea of what is/is not important here from which to judge.
7 Comments
dpb
on 8 Feb 2023
Yeah, @Walter Roberson; I don't know why I tend to forget about nnz -- just 30-yr old habits die slowly, I guess, mostly. It's the better idiom; I should remember using it.
Walter Roberson
on 8 Feb 2023
A = [1 2 3]
B = [18 42 17 3 14 11 (1+eps)]
[found, idx] = ismembertol(A,B)
You can see from this that ismembertol() does not operate element-wise. Each member of the first matrix is compared to each element of the second matrix.
If you want to compare element-by-element then if all of the elements are in the same range, then
num_matches = nnz(abs(A-B) <= tolerance)
ismembertol() is for the case where each element of A is to be compared to all elements of B
When you do not pass a tolerance factor into ismembertol() then it uses 1e-12 (double) or 1e-6 (single) . If you use the datascale option you can specify a tolerance per column when ByRows option is used.
See Also
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!