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

조회 수: 22 (최근 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 CenterFile Exchange에서 Descriptive Statistics에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by