How to find the indices of a point on a curve
3 次查看(过去 30 天)
显示 更早的评论
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/151144/image.png)
Hi I have a curve with one maximum,I need to find the indices of the the two 0.707 points. Thanks
0 个评论
回答(3 个)
dpb
2015-10-28
If you have the curve as computed points, see
doc interp1
Switch the normal X,Y meanings to interpolate with Y as the independent variable instead of X in this case. Also, NB: You'll need to do this in two separate calls, one with the values to the left and another with those to the right of the maximum as interp1 must have unique values for the interpolating function.
This will solve for the precise location; not necessarily integer. If you want the nearest index, then either a) round the above results or b) use
[~,ix]=min(abs(y-sqrt(2)/2*ymax));
Again you'll have to do the above piecewise accounting for the length of the subvectors in the returned indices as there's no guarantee the locations will be symmetric or the same on both sides except under very particular circumstances.
3 个评论
Thorsten
2015-10-29
编辑:Thorsten
2015-10-29
If y is your curve, in general you will not have values that are exactly 0.707 of your maximum. So the idea is to use the 2 values that differ the least from the desired value 0.707*max(y):
[~, idx] = sort(abs(y-0.707*max(y)));
idx = idx(1:2);
4 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Interpolation 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!