How can I put the values of the y-axis in a vector and find the maximum?

조회 수: 6 (최근 30일)
This is my MATLAB code:
data=csvread("abc.CSV");
[H, f]=make_fft(data(:,2),data(:,1)); %my function
figure
stem(f,H)
set(gca,'xscale','log')
How can I see values of the plot in a vector? I should find the first and second maximum along the y axis
  댓글 수: 2
Enrico Gambini
Enrico Gambini 2022년 2월 16일
Hello.
I did not fully understand your question. The values of the y-axis are stored inside vector "H", you mean that you want to see a better scale in the y-axis?
Lorenza Curcio
Lorenza Curcio 2022년 2월 16일
if I look for the maximum of H I get the maximum value, but what if I want the second largest value?

댓글을 달려면 로그인하십시오.

채택된 답변

Enrico Gambini
Enrico Gambini 2022년 2월 16일
You mean this?
H_sorted=sort(H); %sort vector "H" in ascending order
idx=find(H==H_sorted(end-1)); %find the index of the second maximum value in vector "H"
2nd_max_value=H(idx); %this is the second maximum value of vector "H"
  댓글 수: 2
Lorenza Curcio
Lorenza Curcio 2022년 2월 17일
yes, ty
and how can I display the values ​​of the x axis corresponding to those of the y axis? I mean the full list and not just the maximum
because I want to find which value of the x axis corresponds to the second maximum of the y axis
Enrico Gambini
Enrico Gambini 2022년 2월 17일
If you want to find the x-axis value of the second maximum y value you can Just:
x_2ndmax=f(idx)

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Line Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by