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:
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

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