Get multiple indices coinciding closest to a certain value
3 次查看(过去 30 天)
显示 更早的评论
Hello all,
I have an x by 2 array- it is a freq vs amplitude graph. The graph is similar in shape to a typical ideal frequency curve (going uphill to a peak point then downhill).
I am trying to write a code that will detect the half power of the amplitude, and display the frequency of the two half power locations(since it goes up and down).
With some research(stackoverflow forums), I was able to devise a code utilizing the minimum difference between the value and half power value, but this code approach only can get me the first half power point- any help in getting the second one as well will be of great help. Thanks!
the code portion is below:
%halfpow is the number I want to be searched for
%v1 is the column vector that contains the amplitudes
val=abs(v1-halfpow);
[ind ind]=min(val);
closest=v1(ind)
0 个评论
采纳的回答
Guru
2013-7-4
The code you have is fine, what you have are two minima values that you are seeking. So by breaking up your search points you can find it easier. What you
va1 = abs(v1-halfpow); % This part is exactly what you want like above
[C,ind1] = min(val);
point1 = v1(ind1)
% Remove the data points that you just found the minimum of to find another
val(ind-2:ind+2) = max(val);
[C,ind2] = min(val);
point2 = v1(ind2)
This should give you the idea. The concept is min finds the first global minimum of the vector. To find a second minimum, you need to ensure the first minimum is no longer a minimum.
HTH!
更多回答(1 个)
the cyclist
2013-7-4
You could use sort(val) rather than min(val), and you will get the sorted values, and the indices to them.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Multirate Signal Processing 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!