From: James Tursa on
"sean " <jssweeney(a)widener.edu> wrote in message <hkvliv$f3s$1(a)fred.mathworks.com>...
> What is the simplest way to do this?
> x=1
> y=2
> I want to assign the larger number to 'c'. I can think of a few ways, but there must be an easier way. Any builtin to handle this? Thanks.

Hmmm ... so you want to assign the max of the two values to c ... hmmm ... the max of the two values to c ... that's a tough one ...


From: Matt Fig on
Or simply

c = max(x,y)
From: sean on
Thank you for the reply. I thought 'max' would work too, but I get either of these two errors depending on the integer status of x and y. Any ideas?
============
EDU>> x=1
x =
1
EDU>> y=2
y =
2
EDU>> max([x y])
??? Index exceeds matrix dimensions.

EDU>> x=1.1
x =
1.1000
EDU>> y=2.2
y =
2.2000
EDU>> max([x y])
??? Subscript indices must either be real positive integers or logicals.
=============

ImageAnalyst <imageanalyst(a)mailinator.com> wrote in message <f9ecaae3-fb0e-4817-8083-db2876714abf(a)b2g2000yqi.googlegroups.com>...
> c = max([x y])
From: sean on
EDU>> x=1
x =
1
EDU>> y=2
y =
2
EDU>> c=max(x,y)
??? Index exceeds matrix dimensions.

"Matt Fig" <spamanon(a)yahoo.com> wrote in message <hkvm3t$i90$1(a)fred.mathworks.com>...
> Or simply
>
> c = max(x,y)
From: Jan Simon on
Dear Sean!

> EDU>> x=1
> EDU>> y=2
> EDU>> max([x y])
> ??? Index exceeds matrix dimensions.

You have shadowed the function "max" by a variable which is called "max" also. Solution:
clear max
max(x, y)
It's recommended to avoid using function names a names of variables.

Kind regards, Jan