Thread Subject: isfinite to find max w/o including Inf

Subject: isfinite to find max w/o including Inf

From: Diego Zegarra

Date: 28 Oct, 2008 17:42:02

Message: 1 of 2

Could someone please tell me whats wrong with my code?

h = MTT{m}(MSchJ{m}(end),:);
MAXP = [MAXP; max(h(isfinite(MTT{m}(MSchJ{m}(end),:)),1))];

This is the error I get:

??? Index exceeds matrix dimensions.

Error in ==> SAPSLMETARAPS at 197
            MAXP = [MAXP; max(h(isfinite(MTT{m}(MSchJ{m}(end),:)),1))];


Thanks,

Diego

Subject: isfinite to find max w/o including Inf

From: Walter Roberson

Date: 28 Oct, 2008 21:33:01

Message: 2 of 2

"Diego Zegarra" <diegozbb@gmail.com> wrote in message <ge7ita$jdd$1@fred.mathworks.com>...
> Could someone please tell me whats wrong with my code?

> h = MTT{m}(MSchJ{m}(end),:);
> MAXP = [MAXP; max(h(isfinite(MTT{m}(MSchJ{m}(end),:)),1))];

That is equivalent to

MAXP = [MAXP; max(h(isfinite(h),1))];

Did you perhaps mean

MAXP = [MAXP; max(h(isfinite(h)),1)];

that is, taking the maximum along the first dimension
rather than access the first column of h?

We can see from the definition of h that is expected
to be exactly one entire row, so it is going to be 1 x something.
isfinite(h) would be the same size, 1 x something.
You then use that 1 x something logical array as the -first-
index of h rather than as the -second- index of h, as if you
were attempting to access a something x 1 array. And since it
doesn't have all those rows and you explicitly specified the
second dimension it knows that you aren't just using logical
indexing relative to the beginning of the array... so it bombs out.

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
isfinite Diego Zegarra 28 Oct, 2008 13:45:04
max Diego Zegarra 28 Oct, 2008 13:45:04
rssFeed for this Thread

Contact us at files@mathworks.com