How to find the location of approximately equal value in vector?

조회 수: 46 (최근 30일)
I having Z =10.7000 and ACF(auto correlation function)
ACF =
Columns 1 through 6
0 -1.0000 -1.8478 -2.2678 -2.0719 -1.2071
Columns 7 through 12
0.2242 1.9749 3.6955 5.0000 5.5433 5.0962
Columns 13 through 18
3.6027 1.2071 -1.7549 -4.8033 -7.3910 -9.0000
Columns 19 through 24
-9.2388 -7.9246 -5.1334 -1.2071 3.2856 7.6317
Columns 25 through 30
11.0866 13.0000 12.9343 10.7530 6.6641 1.2071
here i want to find out approximately equal value of Z in ACF and also location of the ACF value. Here the Z value is approximately equal to 10.7530 of ACF and it present at location of ACF(28). Help me to write the code for find approximately equal value of Z in ACF and its location(28).

채택된 답변

Stephen23
Stephen23 2017년 2월 3일
편집: Stephen23 2017년 2월 3일
You should calculate the absolute differences, and then use min to get the closest value:
>> Z = 10.7000;
>> ACF = [0,-1.0000,-1.8478,-2.2678,-2.0719,-1.2071,0.2242,1.9749,3.6955,5.0000,5.5433,5.0962,3.6027,1.2071,-1.7549,-4.8033,-7.3910,-9.0000,-9.2388,-7.9246,-5.1334,-1.2071,3.2856,7.6317,11.0866,13.0000,12.9343,10.7530,6.6641,1.2071]
>> [~,idx] = min(abs(Z-ACF))
idx =
28
>> out = ACF(idx)
out = 10.753
  댓글 수: 13
vinod kumar govindu
vinod kumar govindu 2017년 2월 10일
편집: vinod kumar govindu 2017년 2월 10일
I am using MATLAB 7.6.0(R2008a)
and for
syms IRx1 QRx1
also it showing same error
Walter Roberson
Walter Roberson 2017년 2월 10일
It sounds as if you do not have a symbolic toolbox installed, so I do not understand why your earlier code used syms. symsum cannot be used without the Symbolic Toolbox.
It did not make sense to me that you used syms there anyhow.
j = sqrt(-1);
n = 1 : 128;
for i=1:128
this_entry = sum( (IRx1(n) + j.*QRx1(n)) .* (IRx1(n-i) - j.*QRx1(n-i)) );
ACF1(i) = this_entry
end
However, this will have the problem I described before. You are allowing i to exceed n, which is going to lead to negative subscripts.
I suspect your code should look more like
plain = complex(IRx1, QRx1);
for i = 1 : 128
this_entry = sum( plain .* circshift(plain, [1 i]);
ACF1(i) = this_entry;
end

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Conversion Between Symbolic and Numeric에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by