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

12 views (last 30 days)
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).

Accepted Answer

Stephen23
Stephen23 on 3 Feb 2017
Edited: Stephen23 on 3 Feb 2017
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 Comments
vinod kumar govindu
vinod kumar govindu on 10 Feb 2017
Edited: vinod kumar govindu on 10 Feb 2017
I am using MATLAB 7.6.0(R2008a)
and for
syms IRx1 QRx1
also it showing same error
Walter Roberson
Walter Roberson on 10 Feb 2017
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

Sign in to comment.

More Answers (0)

Categories

Find more on Symbolic Math Toolbox in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!