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

### How to find largest value?

• Email
• 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
Reply Peng 3/22/2010 7:16:05 PM

See related articles to this posting

```"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
Reply Husam 3/22/2010 7:35:05 PM

```"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?

Hi, did you read

>>doc max

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

Wayne
```
 0
Reply Wayne 3/22/2010 7:40:20 PM

```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
Reply Loren 3/22/2010 7:41:28 PM

```"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
Reply kk 3/22/2010 7:46:02 PM

```"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
Reply Peng 3/22/2010 8:05:07 PM

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

Really BAD practice.
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
Reply Oleg 3/22/2010 8:22:02 PM

```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
Reply Matt 3/22/2010 9:13:03 PM

7 Replies
980 Views

Similar Articles

12/6/2013 3:45:59 PM
page loaded in 35483 ms. (0)

 Reply:

Similar Artilces: