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:
Quick question regarding max and isfinite

Subject: Quick question regarding max and isfinite

From: Diego Zegarra

Date: 25 Jan, 2009 22:23:02

Message: 1 of 3

I just have a quick question,

if h = [121 Inf 125 175 141 176]

What is this line of text going to do?

MaxTimeL = max(max(h(isfinite(h)),1));

What value is MaxTimeL obtaining? Is it 176?

I am trying to look for the maximum finite number in h. Please let me know if this line of code is correct or not.

Thanks so much!

Subject: Quick question regarding max and isfinite

From: Logan

Date: 25 Jan, 2009 23:37:10

Message: 2 of 3


"Diego Zegarra" <diegozbb@gmail.com> wrote in message
news:glioo6$srl$1@fred.mathworks.com...
>I just have a quick question,
>
> if h = [121 Inf 125 175 141 176]
>
> What is this line of text going to do?
>
> MaxTimeL = max(max(h(isfinite(h)),1));
>
> What value is MaxTimeL obtaining? Is it 176?
>
> I am trying to look for the maximum finite number in h. Please let me know
> if this line of code is correct or not.
>
> Thanks so much!

as h is a vector, may be enough:
max(h(isfinite(h)))

Greetings,
Emidio Marchese

Subject: Quick question regarding max and isfinite

From: Steven Lord

Date: 26 Jan, 2009 14:36:15

Message: 3 of 3


"Diego Zegarra" <diegozbb@gmail.com> wrote in message
news:glioo6$srl$1@fred.mathworks.com...
>I just have a quick question,
>
> if h = [121 Inf 125 175 141 176]
>
> What is this line of text going to do?
>
> MaxTimeL = max(max(h(isfinite(h)),1));
>
> What value is MaxTimeL obtaining? Is it 176?
>
> I am trying to look for the maximum finite number in h. Please let me know
> if this line of code is correct or not.

When trying to figure out what code is doing, usually you want to start from
the inside out.

Do you know what "isfinite(h)" does? If not, look at "help isfinite".

Once you know what "isfinite(h)" does, do you know what "h(isfinite(h))"
does? If not, try it out and take a guess, and then search for "logical
indexing" in the help. [Knowing to look for "logical indexing" is a bit of
a jump, but if you didn't know about logical indexing I would expect you to
ask specifically what "h(isfinite(h))" does, and then someone would point
you to logical indexing.]

Once you know what "h(isfinite(h))" does, do you know what
"max(h(isfinite(h)), 1)" does? If not, look at "help max".

Now, given that you know what "max(h(isfinite(h)), 1)" does, do you know
what the full expression does?

--
Steve Lord
slord@mathworks.com

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