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 max of a vector with Infs

Subject: Finding max of a vector with Infs

From: Diego Zegarra

Date: 22 Feb, 2009 20:00:19

Message: 1 of 4

Suppose you have a vector,

r=[1 2 3 Inf 4]

and want to find the maximum finite number in r and its position.

[a b] = max(r(isfinite(r)))

returns a a=4,b=4, as appearently it is deleting the row with the Inf. How can I get this to be a=4, b=5???

Thanks!

Subject: Finding max of a vector with Infs

From: Donn Shull

Date: 22 Feb, 2009 20:14:01

Message: 2 of 4

"Diego Zegarra" <diegozbb@gmail.com> wrote in message <gnsasj$ign$1@fred.mathworks.com>...
> Suppose you have a vector,
>
> r=[1 2 3 Inf 4]
>
> and want to find the maximum finite number in r and its position.
>
> [a b] = max(r(isfinite(r)))
>
> returns a a=4,b=4, as appearently it is deleting the row with the Inf. How can I get this to be a=4, b=5???
>
> Thanks!

[a,b] = max(r.*isfinite(r))

Subject: Finding max of a vector with Infs

From: Loren Shure

Date: 24 Feb, 2009 14:50:26

Message: 3 of 4

In article <gnsbm9$bee$1@fred.mathworks.com>,
donn.shull.no_spam@aetoolbox.com says...
> "Diego Zegarra" <diegozbb@gmail.com> wrote in message <gnsasj$ign$1@fred.mathworks.com>...
> > Suppose you have a vector,
> >
> > r=[1 2 3 Inf 4]
> >
> > and want to find the maximum finite number in r and its position.
> >
> > [a b] = max(r(isfinite(r)))
> >
> > returns a a=4,b=4, as appearently it is deleting the row with the Inf. How can I get this to be a=4, b=5???
> >
> > Thanks!
>
> [a,b] = max(r.*isfinite(r))
>

would this work with negative numbers?

--
Loren
http://blogs.mathworks.com/loren

Subject: Finding max of a vector with Infs

From: Matt

Date: 24 Feb, 2009 15:48:03

Message: 4 of 4

"Diego Zegarra" <diegozbb@gmail.com> wrote in message <gnsasj$ign$1@fred.mathworks.com>...
> Suppose you have a vector,
>
> r=[1 2 3 Inf 4]
>
> and want to find the maximum finite number in r and its position.
>
> [a b] = max(r(isfinite(r)))
>
> returns a a=4,b=4, as appearently it is deleting the row with the Inf. How can I get this to be a=4, b=5???
>
> Thanks!

a=max(r(isfinite(r)));
b=find(r==a);

Tags for 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