Strange error message using sort( ) ?

Hey
I am trying to locate the 10 fundamental frequencies in my power-spectrum. I know, I can find the peaks, by using the findpeaks() function. Then, I would like to sort these peaks and index them. I thought the following code would do this, but I get an error message I don't understand?
>> Y=abs(fft(channel1)); >> nyquist=ceil(length(Y)/2); >> peaks=findpeaks(Y(1:nyquist)); >> [A,I]=sort(peaks) Indexing cannot yield multiple results.

 採用された回答

Stephen23
Stephen23 2015 年 8 月 14 日
編集済み: Stephen23 2015 年 8 月 14 日

0 投票

You have defined a variable called sort, and this is shadowing (i.e. hiding) the inbuilt sort function. MATLAB uses your sort variable and tries to index into it using the variable peaks, but it gets confused by the multiple outputs that you request.
The solution: do not use inbuilt function names for naming variables or functions. You can clear your workspace to remove the variables, and in future use which to check if a name is already used.

その他の回答 (0 件)

カテゴリ

質問済み:

2015 年 8 月 14 日

編集済み:

2015 年 8 月 14 日

Community Treasure Hunt

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

Start Hunting!

Translated by