How to allow user to retrieve indices for particular value in an array, not the value itself?

1 次查看(过去 30 天)
I want to allow a user to index for a value closest to their input value within a table.
I have an Faxis, which I created from performing an FFT, so this does not have rounded values. I would like the user to be able to input a frequency, say 1000Hz and then for the program to locate the nearest frequency in the array.
As the program needs to use the index and not the value itself at a later point, how can I get this, as I can only see people finding the actual value on here?
Faxis = linspace(0,20e3,30e3) %For example only
Frequency_Index = 1000;
Index = find(min(abs(faxis-Frequency_Index))
The closest I have seen is using the find function but even then it seems to just retrieve the value itself, which is of no use here.

采纳的回答

Dennis
Dennis 2018-11-9
In your example you use the find function on only 1 value ( min() returns 1).
You were close, min() can actually return the index on its own.
[~,idx]=min(abs(faxis-Frequency_Index))

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Matrix Indexing 的更多信息

标签

产品


版本

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by