Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Finding and Graphing Second Max on Graph

Subject: Finding and Graphing Second Max on Graph

From: Jason

Date: 10 Mar, 2011 20:27:05

Message: 1 of 3

Hello all,

I am a new MATLAB user and doing a FFT and Power Spectrum Analysis on some data. I know how to find and graph the maximum point, but cannot figure out how to do the same for the 2nd. Here is the code I am using

in terms of (f,Py)
index=find(Py==max(Py));
    PrimaryPeriodStr=num2str(f(index));
    plot(f(index),Py(index),'r.','MarkerSize',25);
    text(f(index)+.01,Py(index),['Period = ',PrimaryPeriodStr]);

and also
[Pymx,loc] = max(Py)
fmx = f(loc)

How do I go about plotting the 2nd maximum on the same graph? and find the x and y values as well?
Thanks

Subject: Finding and Graphing Second Max on Graph

From: Sean de

Date: 10 Mar, 2011 20:40:08

Message: 2 of 3

"Jason " <Jay75317.remove@yahoo.com> wrote in message <ilbc6o$bcr$1@fred.mathworks.com>...
> Hello all,
>
> I am a new MATLAB user and doing a FFT and Power Spectrum Analysis on some data. I know how to find and graph the maximum point, but cannot figure out how to do the same for the 2nd. Here is the code I am using
>
> in terms of (f,Py)
> index=find(Py==max(Py));
> PrimaryPeriodStr=num2str(f(index));
> plot(f(index),Py(index),'r.','MarkerSize',25);
> text(f(index)+.01,Py(index),['Period = ',PrimaryPeriodStr]);
>
> and also
> [Pymx,loc] = max(Py)
> fmx = f(loc)
>
> How do I go about plotting the 2nd maximum on the same graph? and find the x and y values as well?
> Thanks

tool:
doc sort

use:
sort descending, extract 2nd element. The second output from sort will allow you to know the original index.

Subject: Finding and Graphing Second Max on Graph

From: Miroslav Balda

Date: 10 Mar, 2011 21:03:05

Message: 3 of 3

"Jason " <Jay75317.remove@yahoo.com> wrote in message <ilbc6o$bcr$1@fred.mathworks.com>...
> Hello all,
>
> I am a new MATLAB user and doing a FFT and Power Spectrum Analysis on some data. I know how to find and graph the maximum point, but cannot figure out how to do the same for the 2nd. Here is the code I am using
>
> in terms of (f,Py)
> index=find(Py==max(Py));
> PrimaryPeriodStr=num2str(f(index));
> plot(f(index),Py(index),'r.','MarkerSize',25);
> text(f(index)+.01,Py(index),['Period = ',PrimaryPeriodStr]);
>
> and also
> [Pymx,loc] = max(Py)
> fmx = f(loc)

Hi Jason
You may do it in 3 lines:

[P1,i1] = max(Py);
[P2,i2] = max(Py(Py~=P1));
plot(f(i1),P1,'.r', f(i2),P2,'.m');

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us