How to find the maximum value between two indices in an array?

24 ビュー (過去 30 日間)
Brianna Miranda
Brianna Miranda 2022 年 10 月 28 日
編集済み: Chunru 2022 年 10 月 28 日
I am trying to find the maximum power spectrum value between two indices in an array that correspond to specific frequencies in another array. mode2a and mode2b are the frequency range that I want to find the maximum power spectrum value for. In my code all of the lines give me the correct outputs except for the last two lines where I try to output the frequency value that corresponds to the maximum power spectrum. Can anyone see what is causing the last two lines to return incorrect values?
mode2a = 200; % frequency lower bound (Hz)
mode2b = 600; % frequency upper bound (Hz)
indexA = find(f_data==mode2a); % index that corresponds to frequency lower bound
indexB = find(f_data==mode2b); % index that corresponds to frequency upper bound
[amp,indMax] = max(P1_data(indexA:indexB)); % find maximum value within the indexA-indexB range and its index
freq = f_data(indMax); % compute the frequency that corresponds to the index of the max value of the power spectrum

採用された回答

Chunru
Chunru 2022 年 10 月 28 日
編集済み: Chunru 2022 年 10 月 28 日
Without yor data and complete code, this is a guess:
mode2a = 200; % frequency lower bound (Hz)
mode2b = 600; % frequency upper bound (Hz)
indexA = find(f_data>=mode2a, 1, 'first'); % index that corresponds to frequency lower bound
indexB = find(f_data<=mode2b, 1, 'last'); % index that corresponds to frequency upper bound
[amp,indMax] = max(P1_data(indexA:indexB)); % find maximum value within the indexA-indexB range and its index
freq = f_data(indexA-1+indMax); % compute the frequency that corresponds to the index of the max value of the power spectrum

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeDescriptive Statistics についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by