Thread Subject: how to Vectorize IF statement?

Subject: how to Vectorize IF statement?

From: happydude Hudson

Date: 9 Nov, 2009 14:14:02

Message: 1 of 3

I have a two column vectors (Vector A and Vector B).

Both are randomly assigned 1 or 0 for each row.

I want to use a vectorized if statement to test if each row of A equals the corresponding row of B and put the output in a corresponding row of Vector C.

ie. column Vector C will end up being something like:
"true"
"false"
"false"
"true"

etc

how would I do this?

Subject: how to Vectorize IF statement?

From: Titus Edelhofer

Date: 9 Nov, 2009 14:15:51

Message: 2 of 3


"happydude Hudson" <hud_wa@hotmail.com> schrieb im Newsbeitrag
news:hd983a$782$1@fred.mathworks.com...
>I have a two column vectors (Vector A and Vector B).
>
> Both are randomly assigned 1 or 0 for each row.
>
> I want to use a vectorized if statement to test if each row of A equals
> the corresponding row of B and put the output in a corresponding row of
> Vector C.
>
> ie. column Vector C will end up being something like:
> "true"
> "false"
> "false"
> "true"
>
> etc
>
> how would I do this?
>

if they are vectors then C should just be
C = (A == B)

Titus
( ) are not necessary, just to make it more readable ...

Subject: how to Vectorize IF statement?

From: happydude Hudson

Date: 9 Nov, 2009 14:48:02

Message: 3 of 3

so simple...
 awesome!

thanks!

"Titus Edelhofer" <titus.edelhofer@mathworks.de> wrote in message <hd986n$e47$1@fred.mathworks.com>...
>
> "happydude Hudson" <hud_wa@hotmail.com> schrieb im Newsbeitrag
> news:hd983a$782$1@fred.mathworks.com...
> >I have a two column vectors (Vector A and Vector B).
> >
> > Both are randomly assigned 1 or 0 for each row.
> >
> > I want to use a vectorized if statement to test if each row of A equals
> > the corresponding row of B and put the output in a corresponding row of
> > Vector C.
> >
> > ie. column Vector C will end up being something like:
> > "true"
> > "false"
> > "false"
> > "true"
> >
> > etc
> >
> > how would I do this?
> >
>
> if they are vectors then C should just be
> C = (A == B)
>
> Titus
> ( ) are not necessary, just to make it more readable ...
>

Tags for this Thread

Add a New Tag:

Separated by commas
Ex.: root locus, bode

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.

rssFeed for this Thread

Contact us at files@mathworks.com