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

Souparno Bandyopadhyay
Souparno Bandyopadhyay 2012년 12월 9일
I am comparing A to B and then A to C, I need a single number that will allow me to quickly judge A resembles B or C.
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
Matt Fig 2012년 12월 9일

0 개 추천

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

Souparno Bandyopadhyay
Souparno Bandyopadhyay 2012년 12월 9일
편집: Walter Roberson 2012년 12월 9일
A, B, C are vectors of length 4. They are coefficients of a linear prediction filter.
say A = [1 2 3 4]
and B = [1.1 2.2 3.3 4.4]
and C = [1 2 3 4.5]
so if
i = 1:4
delta = (A[i] - B[i]);
sum = sum + delta;
end
% i want the minimum value of sum for 512 iterations. but I want to know if there exists a function that would allow me to replace the for loop.
Matt Fig
Matt Fig 2012년 12월 9일
편집: Matt Fig 2012년 12월 9일
Souparno, that is not valid MATLAB code. But if it were transformed to valid code such that you are after variable S. (You should not name a variable sum because this will mask the MATLAB function SUM. Same goes for i.)
S = 0;
for ii = 1:4
delta = (A(ii) - B(ii));
S = S + delta;
end
This can be replaced by:
S = sum(A-B)
I have no idea what you mean by 512 iterations. You mean the real vectors are 512 elements instead of 4?
Souparno Bandyopadhyay
Souparno Bandyopadhyay 2012년 12월 9일
I am using lpc(x,4), x is a set of discrete data to get 4 coeff vector of a linear prediction filter. Then I am comparing these coeff to another set that i get from executing lpc over another part of the same x(n) to find which two parts resemble the closest.
Jan
Jan 2012년 12월 9일
@Souparno: Accepting an answer means that the problem is solved. Is this true here?
Souparno Bandyopadhyay
Souparno Bandyopadhyay 2012년 12월 10일
yes, S = sum(A-B), is what I was looking for.

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

추가 답변 (1개)

Greg Heath
Greg Heath 2012년 12월 10일

14 개 추천

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

카테고리

도움말 센터File Exchange에서 Historical Contests에 대해 자세히 알아보기

태그

질문:

2012년 12월 9일

댓글:

2022년 2월 2일

Community Treasure Hunt

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

Start Hunting!

Translated by