# Compare two vectors for similarity

조회 수: 506 (최근 30일)
Souparno Bandyopadhyay . 2012년 12월 9일
댓글: maxanto . 2022년 2월 2일
How to compare two vectors quickly. Right now I print out each in a loop and examine them by eye, is there a way i can find if two are almost similar.
##### 댓글 수: 2표시 이전 댓글 수: 1숨기기 이전 댓글 수: 1
maxanto 2022년 2월 2일
isequal(a, b)
Returns true if each element of vector a is equal to each element of vector b. If some element of a are different from b returns false.

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

### 채택된 답변

Matt Fig 2012년 12월 9일
What is the criteria for 'almost similar' in your application? 90% same exact values? 90% of the values in one vector within 95% of some other value in the other vector? Do the values have to be in the same positions? Do the vectors have to be the same length? Perhaps a few short examples would help...
##### 댓글 수: 5표시 이전 댓글 수: 4숨기기 이전 댓글 수: 4
yes, S = sum(A-B), is what I was looking for.

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

### 추가 답변 (1개)

Greg Heath 2012년 12월 10일
S = sum(A-B) is NOT a useful function for quantifying similarity because positive and negative terms will cancel.
The most common are
mae(A-B) % mean(abs(A-B))
sae(A-B) % sum(abs(A-B))
norm(A-B,1) % sum(abs(A-B))
norm(A-B,inf) % max(abs(A-B))
mse(A-B) % mean((A-B).^2)
sse(A-B) % sum((A-B).^2)
norm(A-B) % sqrt(sse(A-B))
Hope this helps.
Thank you for formally accepting my answer
Greg

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

### 카테고리

Help CenterFile Exchange에서 Matched Filter and Ambiguity Function에 대해 자세히 알아보기

### Community Treasure Hunt

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

Start Hunting!