필터 지우기
필터 지우기

Place(s) of greatest deviation

조회 수: 1 (최근 30일)
Ulrik Nash
Ulrik Nash 2011년 5월 15일
Hi Everyone,
Suppose I have a vector Y:
Y = [0 0 0 0.5 0.5]
and a vector X
X = [0 0 0 1 1]
Now I wish to find the place of greatest (absolute) deviation between Y and X. Now, there are two such places, but if I use the following:
[~,I] = max(abs(X-Y))
then the answer is always 4. But 5 has an equally large deviation. What I really wish in such ties is to be returned a random place (out of the ties).
Any hints how to solve this problem?
Regards,
Ulrik.

답변 (1개)

Oleg Komarov
Oleg Komarov 2011년 5월 15일
Y = [0 0 0 0.5 0.5];
X = [0 0 0 1 1];
absdiff = abs(X-Y);
pos = find(max(absdiff) == absdiff); % or [trash,pos] = ismember(max(absdiff),absdiff);
pos(randi(numel(pos),1))
Try to execute several times to see the random selection between position 4 and 5.

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by