如何在原始数组中查找已排序数据的索引?

时间:2014-04-28 09:41:28

标签: matlab sorting

让我们考虑以下代码

>> B=xlsread('data_generations1','A1','g8:g301');
>> [pxx,f]=periodogram(B,[],[],100);
>> [peaks,location]=findpeaks(pxx);
>> [sorted_peaks,i]=sort(peaks,'descend');
>> stem(sorted_peaks)
>> plot(location,peaks)
>> plot(f,pxx)
>> 

我的目标是根据排序的峰值排列频率,我已经将它降序排序,所以我的目标是首先应该是最大sort_peak发生的频率等等,那么我该如何管理呢?谢谢提前

EDITED: 这是正确的方法吗?

>> freq=f(location);
>> freq(i)

2 个答案:

答案 0 :(得分:1)

据我所知,你的编辑确实是正确的方法:

>> freq_peaks        = f(location);
>> sorted_freq_peaks = freq_peaks (i);

答案 1 :(得分:1)

据我了解,

location(i) 

会给出匹配峰的排序顺序。

所以

sorted_locations = locations(i)
plot(sorted_locations, sorted_peaks)

会给你匹配的情节。

相关问题