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:
Matrix threshold

Subject: Matrix threshold

From: lesodk Zokla

Date: 7 May, 2009 16:26:01

Message: 1 of 5

I have a matrix with random values.

I want to set the values below zeros to 0 and values exceeding one to 1.
Right now i use

    idmax = (A >= 1);
    idmin = (A <= 0);
   A(idmax) = 1;
   A(idmin) = 0;

i just find it to slow. Can anyone do it more efficiently?

Subject: Matrix threshold

From: Yi Cao

Date: 7 May, 2009 16:50:18

Message: 2 of 5

"lesodk Zokla" <lesodk@gmail.com> wrote in message <gtv22p$5kq$1@fred.mathworks.com>...
> I have a matrix with random values.
>
> I want to set the values below zeros to 0 and values exceeding one to 1.
> Right now i use
>
> idmax = (A >= 1);
> idmin = (A <= 0);
> A(idmax) = 1;
> A(idmin) = 0;
>
> i just find it to slow. Can anyone do it more efficiently?

A = min(max(A, 0), 1);

HTH
Yi Cao

Subject: Matrix threshold

From: ImageAnalyst

Date: 7 May, 2009 16:51:50

Message: 3 of 5

On May 7, 12:26 pm, "lesodk Zokla" <les...@gmail.com> wrote:
> I have a matrix with random values.
>
> I want to set the values below zeros to 0 and values exceeding one to 1.
> Right now i use
>
>     idmax = (A >= 1);
>     idmin = (A <= 0);
>    A(idmax) = 1;
>    A(idmin) = 0;
>
> i just find it to slow. Can anyone do it more efficiently?

--------------------------------------------------------------------
Just how slow? Give me some times. On my computer it's faster than a
blink of an eye. For me, with a million array elements (1000x1000) it
takes only 0.05 seconds. Seems pretty fast to me. Maybe you need to
cut back on your caffeine intake. How big is your A? Hundreds of
millions of elements?

Subject: Matrix threshold

From: John D'Errico

Date: 7 May, 2009 17:04:01

Message: 4 of 5

ImageAnalyst <imageanalyst@mailinator.com> wrote in message <f53b192f-4c19-4432-a285-d5a4f917eaf2@g31g2000pra.googlegroups.com>...
> Just how slow? Give me some times. On my computer it's faster than a
> blink of an eye. For me, with a million array elements (1000x1000) it
> takes only 0.05 seconds. Seems pretty fast to me. Maybe you need to
> cut back on your caffeine intake. How big is your A? Hundreds of
> millions of elements?

Can you help me? I wanted to speed up my
computer, so I poured coffee (the hi-test stuff)
directly on the mother board.

Not only did this not help, but to my surprise
my computer now wants to "sleep" all the time.

;-)

John

Subject: Matrix threshold

From: lesodk Zokla

Date: 7 May, 2009 17:30:04

Message: 5 of 5

"Yi Cao" <y.cao@cranfield.ac.uk> wrote in message <gtv3ga$dde$1@fred.mathworks.com>...
> "lesodk Zokla" <lesodk@gmail.com> wrote in message <gtv22p$5kq$1@fred.mathworks.com>...
> > I have a matrix with random values.
> >
> > I want to set the values below zeros to 0 and values exceeding one to 1.
> > Right now i use
> >
> > idmax = (A >= 1);
> > idmin = (A <= 0);
> > A(idmax) = 1;
> > A(idmin) = 0;
> >
> > i just find it to slow. Can anyone do it more efficiently?
>
> A = min(max(A, 0), 1);
>
> HTH
> Yi Cao

Magnificent!

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