필터 지우기
필터 지우기

Find similar rows but not equal at the same matrix

조회 수: 2 (최근 30일)
Libros Construccion
Libros Construccion 2017년 5월 17일
편집: Libros Construccion 2017년 5월 17일
Hi,
I have a mx3 matrix and need to find which rows are very close one another. For example
[a b c
d e f
a b c+1e-8
d e f
g h i
g h+1e-5 i
];
ans= [1,3 ; 5,6] %ignoring the rows that hasn't at least one similar. It's something like a min_tol to accept and an max_tol to reject
I've been thinking about tolerances with find(), unique, uniquetol(), intersection(?) or perform some calculations to get it, but i have only figure it out in ways that enlarge too much my data. Any guide Thanks!
  댓글 수: 2
Stephen23
Stephen23 2017년 5월 17일
Why are rows 2 and 4 not listed in your example output?
Libros Construccion
Libros Construccion 2017년 5월 17일
Because i don't want equals rows, just similar ones. unique() clear one of them, but i get row 2 outputted when i try it.

댓글을 달려면 로그인하십시오.

채택된 답변

Libros Construccion
Libros Construccion 2017년 5월 17일
편집: Libros Construccion 2017년 5월 17일
Hey, thanks!. I'll try to follow your guides. Maybe i can combine them with this, which is getting me where i want.
A=[1 2 3; 1+1e-5 2 3; 1 2 3;1+1e-8 2 3];
simA=find(ismember(A,uniquetol(A,1e-6,'ByRows',true),'rows')==0);
ans=4

추가 답변 (1개)

Jan
Jan 2017년 5월 17일
편집: Jan 2017년 5월 17일
pdist replies the pairwise distances between the rows. Then you can filter out the values:
D = pdist(Data);
Match = (D ~= 0 & D < 1e-4);
Without the Statistics Toolbox you can calculate the distance matrix manually also. If the input is not huge, a loop might be useful also, because you can remove the unwanted element directly:
n = 1000;
data = rand(n, 3);
check = true(1, n);
result = zeros(n, 2); % Pre-allocate
iResult = 0;
limit = 1e-4 ^ 2; % Squared limit to avoid SQRT
for k = 1:n
if check(k) % Not included before (is this wanted?!)
dist = sum(data(k, :) - data(k+1:n, :)).^2, 2);
match = find(dist > 0 & dist < 1e-2);
...
end
end
Sorry, I cannot finish this code, because I found some open questions. What should happen for:
a b c
d e f
a b c+1e-4
a+1e-4 b c
Or if the limit is 1e-4, what about this:
a b c
a b c+1e-4
a b c+2e-4
What is the wanted result?
Why does the output have less columns than the input?

카테고리

Help CenterFile Exchange에서 Stress and Strain에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by