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

22 次查看(过去 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 个评论
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 中查找有关 Symbolic Math Toolbox 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by