Get multiple indices coinciding closest to a certain value
显示 更早的评论
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)
采纳的回答
更多回答(1 个)
the cyclist
2013-7-4
0 个投票
You could use sort(val) rather than min(val), and you will get the sorted values, and the indices to them.
类别
在 帮助中心 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!