How to find the maximum value between two indices in an array?
24 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Brianna Miranda
am 28 Okt. 2022
Bearbeitet: Chunru
am 28 Okt. 2022
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
0 Kommentare
Akzeptierte Antwort
Chunru
am 28 Okt. 2022
Bearbeitet: Chunru
am 28 Okt. 2022
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 Kommentare
Weitere Antworten (0)
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!