COMPGROUPS.NET | Search | Post Question | Groups | Stream | About | Register

### How to find largest value?

• Follow

```How can i get the largest value among three variables?

a=100;
b=50;
c=200;

The largest is c, then it will set "max=c"

Can anyone show me how to do it?
```
 0

```"Peng Swee Yap" <impengswee@gmail.com> wrote in message <ho8fll\$t82\$1@fred.mathworks.com>...
> How can i get the largest value among three variables?
>
> a=100;
> b=50;
> c=200;
>
> The largest is c, then it will set "max=c"
>
>
> Can anyone show me how to do it?

arr = [a,b,c];
arr_name = {'a','b','c'};

[maximum,ind] = max(arr);

str = ['max = ',arr_name{ind}];
disp(str)

% the max value is stored in the variable name 'maximum'
```
 0

```"Peng Swee Yap" <impengswee@gmail.com> wrote in message <ho8fll\$t82\$1@fred.mathworks.com>...
> How can i get the largest value among three variables?
>
> a=100;
> b=50;
> c=200;
>
> The largest is c, then it will set "max=c"
>
>
> Can anyone show me how to do it?

>>doc max

Just put those values in a vector and use max()

Wayne
```
 0

```In article <ho8fll\$t82\$1@fred.mathworks.com>, impengswee@gmail.com
says...
> How can i get the largest value among three variables?
>
> a=100;
> b=50;
> c=200;
>
> The largest is c, then it will set "max=c"
>
>
> Can anyone show me how to do it?
>

Place a, b, c in one array and check out the function "max".

--
Loren
http://blogs.mathworks.com/loren
http://matlabwiki.mathworks.com/MATLAB_FAQ
```
 0

```"Peng Swee Yap" <impengswee@gmail.com> wrote in message <ho8fll\$t82\$1@fred.mathworks.com>...
> How can i get the largest value among three variables?
>
> a=100;
> b=50;
> c=200;
>
> The largest is c, then it will set "max=c"
>
>
> Can anyone show me how to do it?

Vector=[a;b;c];
max=max(Vector);
```
 0

```"kk KKsingh" <akikumar1983@gmail.com> wrote in message <ho8hdq\$7c\$1@fred.mathworks.com>...
> "Peng Swee Yap" <impengswee@gmail.com> wrote in message <ho8fll\$t82\$1@fred.mathworks.com>...
> > How can i get the largest value among three variables?
> >
> > a=100;
> > b=50;
> > c=200;
> >
> > The largest is c, then it will set "max=c"
> >
> >
> > Can anyone show me how to do it?
>
>
> Vector=[a;b;c];
> max=max(Vector);

thank you.
```
 0

```> > Vector=[a;b;c];
> > max=max(Vector);
>
> thank you.

Don't use matlab builtin functions as variable names.

To see what I'm talking about try this:
max=max([1 10])
max([20 30 100])

Oleg
```
 0

```I second Oleg's message about variable names.  Also, here is another approach for your problem.

mx = max(a,max(b,c))  % The largest value of scalars a,b,c.
```
 0

7 Replies
760 Views

Similiar Articles:

7/29/2012 12:20:07 PM