Thread Subject: find max & min and write in array

Subject: find max & min and write in array

From: Somnath Karmakar

Date: 1 Jun, 2009 10:41:01

Message: 1 of 3

Hello,
I am very new to Matlab. I have a function F (x) which has (+) and (-) peaks on both sides of x axis i.e the horizontal axis. I would like to array all values of F (x) for both peaks and corresponding x values.
Simply if we consider, F(x) = sin(x), (+) peak value is 1and corresponding x= (pi/2),
and (-) peak value is -1, corresponds to x= (3*pi/2) and so on. Now wish to array of these
for a given range.
Hope to get proper direction how to proceed.

Thanks

Subject: find max & min and write in array

From: Wayne King

Date: 1 Jun, 2009 11:26:02

Message: 2 of 3

Hi Somnath,

Perhaps findpeaks() will work for you? You can use find(). Both will return the locations (x-indices) where the peaks (as you define them) occur.

hope that helps,
wayne

To find the maxima of sin(x) (where you also want the -1 value to be interpreted as a peak)

x = 0:.01:(2*pi);
y = sin(x);
[pks,loc] = findpeaks(abs(y),'minpeakheight',0.9);
loc =

   158 472

% y(158) is equal to 1
x(158) % the x-location is pi/2

ans =

    1.5700

hope that helps,
wayne

"Somnath Karmakar" <somnath1402@rediffmail.com> wrote in message <h00b7t$7jp$1@fred.mathworks.com>...
> Hello,
> I am very new to Matlab. I have a function F (x) which has (+) and (-) peaks on both sides of x axis i.e the horizontal axis. I would like to array all values of F (x) for both peaks and corresponding x values.
> Simply if we consider, F(x) = sin(x), (+) peak value is 1and corresponding x= (pi/2),
> and (-) peak value is -1, corresponds to x= (3*pi/2) and so on. Now wish to array of these
> for a given range.
> Hope to get proper direction how to proceed.
>
> Thanks

Subject: find max & min and write in array

From: Miroslav Balda

Date: 1 Jun, 2009 12:55:03

Message: 3 of 3

"Somnath Karmakar" <somnath1402@rediffmail.com> wrote in message <h00b7t$7jp$1@fred.mathworks.com>...
> Hello,
> I am very new to Matlab. I have a function F (x) which has (+) and (-) peaks on both sides of x axis i.e the horizontal axis. I would like to array all values of F (x) for both peaks and corresponding x values.
> Simply if we consider, F(x) = sin(x), (+) peak value is 1and corresponding x= (pi/2),
> and (-) peak value is -1, corresponds to x= (3*pi/2) and so on. Now wish to array of these
> for a given range.
> Hope to get proper direction how to proceed.
>
> Thanks

Hi,

Such a task solves the function extr.m, which is on FEX Id. 10272. See help extr.

Mira

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

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.

Tag Activity for This Thread
Tag Applied By Date/Time
maximum Somnath Karmakar 1 Jun, 2009 06:44:02
minimum of any ... Somnath Karmakar 1 Jun, 2009 06:44:02
rssFeed for this Thread

Contact us at files@mathworks.com