Skip to Main Content Skip to Search
Login
File Exchange
MATLAB Newsgroup
Link Exchange
  Blogs  
 Contest 
MathWorks.com

Thread Subject: position of the max value in a vector

Subject: position of the max value in a vector

From: lars Man

Date: 04 May, 2008 11:50:05

Message: 1 of 14

Hi all,
my problem is. I got a coulmn vector out of a calculation
with about 10000 rows.
Now i want to know WHERE the maximum value is.

For example:
v= [1; 2; 3; 4; 3; 8; 3];
max(v)

8


but how can I get the position from the max. Here for
example it shoud be 6 (cause of the positon of the max
value. It ist 6).
But i don't know to get it.

Thanks for help

Subject: Re: position of the max value in a vector

From: Lars

Date: 04 May, 2008 12:22:02

Message: 2 of 14

>> help find

Subject: Re: position of the max value in a vector

From: John D'Errico

Date: 04 May, 2008 12:54:04

Message: 3 of 14

"lars Man" <larsman@gmx.net> wrote in message
<fvk7td$ofp$1@fred.mathworks.com>...
> Hi all,
> my problem is. I got a coulmn vector out of a calculation
> with about 10000 rows.
> Now i want to know WHERE the maximum value is.
>
> For example:
> v= [1; 2; 3; 4; 3; 8; 3];
> max(v)
>
> 8
>
>
> but how can I get the position from the max. Here for
> example it shoud be 6 (cause of the positon of the max
> value. It ist 6).
> But i don't know to get it.
>
> Thanks for help

help max

Subject: Re: position of the max value in a vector

From: dpb

Date: 04 May, 2008 13:15:39

Message: 4 of 14

lars Man wrote:
...

> Now i want to know WHERE the maximum value is.
>
> For example:
> v= [1; 2; 3; 4; 3; 8; 3];
> max(v)
>
> 8

doc max

--

Subject: Re: position of the max value in a vector

From: Image Analyst

Date: 04 May, 2008 14:05:07

Message: 5 of 14

"lars Man" <larsman@gmx.net> wrote in message
<fvk7td$ofp$1@fred.mathworks.com>...
> Hi all,
> my problem is. I got a coulmn vector out of a calculation
> with about 10000 rows.
> Now i want to know WHERE the maximum value is.
>
> For example:
> v= [1; 2; 3; 4; 3; 8; 3];
> max(v)
>
> 8
>
>
> but how can I get the position from the max. Here for
> example it shoud be 6 (cause of the positon of the max
> value. It ist 6).
> But i don't know to get it.
>
> Thanks for help

---------------------------------------------------
lars Man:
How about something like:
indexOfMaxValue = find(v==max(v));

Regards,
ImageAnalyst

Subject: Re: position of the max value in a vector

From: dpb

Date: 04 May, 2008 14:09:33

Message: 6 of 14

Image Analyst wrote:
> "lars Man" <larsman@gmx.net> wrote in message
...
>> but how can I get the position from the max.
...
> How about something like:
> indexOfMaxValue = find(v==max(v));

or

[vmax, idx] = max(v);

:)

(max() does return only the first of multiples whereas find() will
return the vector, of course, if that is wanted/needed...)

--

Subject: Re: position of the max value in a vector

From: CandyGirl

Date: 04 May, 2008 17:52:21

Message: 7 of 14

Hi,

If you want the index try:

[maxval, maxind]=max(a)

:)

Subject: Re: position of the max value in a vector

From: aasim Azooz

Date: 05 May, 2008 18:13:02

Message: 8 of 14

"Lars " <mustermann.klaus.TO.REMOVE@gmx.de> wrote in
message <fvk9pa$9cv$1@fred.mathworks.com>...
> >> help find
use
[x,i]=max(A)
x is the maximum value of your vector
i is the index of where the maximum value was found. for
more information type
>> help max

Aasim Azooz
Mosul University
Mosul Iraq

Subject: Re: position of the max value in a vector

From: lars Man

Date: 06 May, 2008 19:49:02

Message: 9 of 14

Thanks a lot to all!!!!!

Subject: Re: position of the max value in a vector

From: lars Man

Date: 06 May, 2008 19:49:03

Message: 10 of 14

Thanks a lot to all!!!!!

Subject: Re: position of the max value in a vector

From: lars Man

Date: 06 May, 2008 19:49:03

Message: 11 of 14

Thanks a lot to all!!!!!

Subject: Re: position of the max value in a vector

From: lars Man

Date: 06 May, 2008 19:50:20

Message: 12 of 14

Thanks a lot to all!!!!!

Subject: Re: position of the max value in a vector

From: lars Man

Date: 06 May, 2008 19:50:20

Message: 13 of 14

Thanks a lot to all!!!!!

Subject: Re: position of the max value in a vector

From: lars Man

Date: 06 May, 2008 19:50:20

Message: 14 of 14

Thanks a lot to all. It works!

Tags for this Thread

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.

rssFeed for this Thread

envelope graphic E-mail this page to a colleague

Public Submission Policy
NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Disclaimer prior to use.
Related Topics