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:
Elements comaprison using ALL statement

Subject: Elements comaprison using ALL statement

From: Liana

Date: 13 May, 2011 19:15:05

Message: 1 of 8

Hi!

>> if all(X(:) < Y(:))
This expression sequentially compares each pair of X and Y elements. But I need to check if each element in X array is smaller than ANY element in Y array. How can I do this?
The following code also doesn't work properly:
>> if all(X(:)) < all(Y(:))
Thanks!

Subject: Elements comaprison using ALL statement

From: Matt J

Date: 13 May, 2011 20:08:05

Message: 2 of 8

"Liana" wrote in message <iqjvvp$3dq$1@newscl01ah.mathworks.com>...
> Hi!
>
> >> if all(X(:) < Y(:))
> This expression sequentially compares each pair of X and Y elements. But I need to check if each element in X array is smaller than ANY element in Y array. How can I do this?
===============


Hint: bsxfun

Subject: Elements comaprison using ALL statement

From: alistair templeton

Date: 13 May, 2011 20:20:07

Message: 3 of 8


> Hint: bsxfun

it also sounds like you could take some shortcuts using min/max, depending on what exactly you want to do

Subject: Elements comaprison using ALL statement

From: James Tursa

Date: 13 May, 2011 20:44:07

Message: 4 of 8

"Liana" wrote in message <iqjvvp$3dq$1@newscl01ah.mathworks.com>...
> Hi!
>
> >> if all(X(:) < Y(:))
> This expression sequentially compares each pair of X and Y elements. But I need to check if each element in X array is smaller than ANY element in Y array. How can I do this?
> The following code also doesn't work properly:
> >> if all(X(:)) < all(Y(:))
> Thanks!

Do you mean this?

if( max(X(:)) < max(Y(:)) )

James Tursa

Subject: Elements comaprison using ALL statement

From: dpb

Date: 13 May, 2011 20:44:51

Message: 5 of 8

On 5/13/2011 2:15 PM, Liana wrote:
...
> I need to check if each element in X array is smaller than ANY element
> in Y array. How can I do this?

max(x)<min(y)

--

Subject: Elements comaprison using ALL statement

From: ImageAnalyst

Date: 13 May, 2011 20:45:09

Message: 6 of 8

On May 13, 3:15 pm, "Liana " <liananapalk...@email.arizona.edu> wrote:
> Hi!
>
> >> if all(X(:) < Y(:))
>
> This expression sequentially compares each pair of X and Y elements. But  I need to check if each element in X array is smaller than ANY element in Y array. How can I do this?
> The following code also doesn't work properly:>> if all(X(:)) < all(Y(:))
>
> Thanks!
----------------------------------------------------------------------------------------
How about something like

% Create two arrays.
% They might be different sizes so make sure it handles that.
y = rand(4,6)+0.9
x = rand(3,7)

% The algorithm
% Could be combined into a single line if desired.
miny = min(y(:))
differences = x-miny % Let's see what it looks like...
highestDiff = max(differences(:))
% Want the above to be all less than zero..
if highestDiff < 0
    message = sprintf('All x are less than min y of %f', miny);
    msgbox(message);
else
    msgbox('At least one y is greater than an x');
end

Subject: Elements comaprison using ALL statement

From: ImageAnalyst

Date: 13 May, 2011 20:47:35

Message: 7 of 8

On May 13, 4:45 pm, ImageAnalyst <imageanal...@mailinator.com> wrote:
> % The algorithm
> % Could be combined into a single line if desired.
---------------------------------
Like James did.... Use his if you want a simple one liner that works
for any array sizes, even different sized arrays.

Subject: Elements comaprison using ALL statement

From: Liana

Date: 16 May, 2011 06:32:04

Message: 8 of 8

Thank you, it is exactly what I was looking for.

ImageAnalyst <imageanalyst@mailinator.com> wrote in message <34b06151-b890-4eed-8463-aede4e6c9cd3@c41g2000yqm.googlegroups.com>...
> On May 13, 3:15 pm, "Liana " <liananapalk...@email.arizona.edu> wrote:
> > Hi!
> >
> > >> if all(X(:) < Y(:))
> >
> > This expression sequentially compares each pair of X and Y elements. But  I need to check if each element in X array is smaller than ANY element in Y array. How can I do this?
> > The following code also doesn't work properly:>> if all(X(:)) < all(Y(:))
> >
> > Thanks!
> ----------------------------------------------------------------------------------------
> How about something like
>
> % Create two arrays.
> % They might be different sizes so make sure it handles that.
> y = rand(4,6)+0.9
> x = rand(3,7)
>
> % The algorithm
> % Could be combined into a single line if desired.
> miny = min(y(:))
> differences = x-miny % Let's see what it looks like...
> highestDiff = max(differences(:))
> % Want the above to be all less than zero..
> if highestDiff < 0
> message = sprintf('All x are less than min y of %f', miny);
> msgbox(message);
> else
> msgbox('At least one y is greater than an x');
> end

Tags for this Thread

No tags are associated with 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