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:
max value of two expressions

Subject: max value of two expressions

From: Ulrik Nash

Date: 27 Apr, 2010 12:10:07

Message: 1 of 4

Hi Everyone,

Suppose I have two expressions

A = B + C

and

D = E + F

Now I simply wish to let G take the value A or D, depending on which of A or D is largest. If A > D, then G = A, and if A < D, then G = D.

How can I do this in a simple expression without using if then?

Cheers

Ulrik.

Subject: max value of two expressions

From: Bruno Luong

Date: 27 Apr, 2010 12:43:04

Message: 2 of 4

"Ulrik Nash" <uwn@sam.sdu.dk> wrote in message <hr6k6v$lr8$1@fred.mathworks.com>...
> Hi Everyone,
>
> Suppose I have two expressions
>
> A = B + C
>
> and
>
> D = E + F
>
> Now I simply wish to let G take the value A or D, depending on which of A or D is largest. If A > D, then G = A, and if A < D, then G = D.
>
> How can I do this in a simple expression without using if then?

The simplest is

max(A,D)

Bruno

Subject: max value of two expressions

From: Ulrik Nash

Date: 27 Apr, 2010 14:03:04

Message: 3 of 4

Thanks Bruno,

When I use the command on my expressions, I get an error message:

"Undefined function or method 'max' for input arguments of type 'struct'."

Why do i get this message?

Cheers

Subject: max value of two expressions

From: Matt Fig

Date: 27 Apr, 2010 14:51:04

Message: 4 of 4

"Ulrik Nash" <uwn@sam.sdu.dk> wrote in message <hr6qqo$eg$1@fred.mathworks.com>...
> Thanks Bruno,
>
> When I use the command on my expressions, I get an error message:
>
> "Undefined function or method 'max' for input arguments of type 'struct'."
>
> Why do i get this message?
>
> Cheers

Well, why *wouldn't* you get that message?

A.food = 'orange';
A.spice = 'nutmeg';

B.food = 'potato';
B.spice = 'clove';

Now, which structure is bigger? Think about it please.

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