Thread Subject: Vector - change all 1's to -1

Subject: Vector - change all 1's to -1

From: happydude

Date: 18 Nov, 2009 20:28:19

Message: 1 of 4

I have a random vector of ones and zeros.
How do I change the 1's to -1's

Subject: Vector - change all 1's to -1

From: Ashish Uthama

Date: 18 Nov, 2009 20:37:59

Message: 2 of 4

On Wed, 18 Nov 2009 15:28:19 -0500, happydude <anonymousse@hotmail.com>
wrote:

> I have a random vector of ones and zeros.
> How do I change the 1's to -1's

Multiply by -1?

Subject: Vector - change all 1's to -1

From: happydude

Date: 18 Nov, 2009 20:42:18

Message: 3 of 4

crikey... ive been looking at this screen way too long..

how do i delete a post from this thing :)

(thanks btw)

Subject: Vector - change all 1's to -1

From: dpb

Date: 18 Nov, 2009 21:24:49

Message: 4 of 4

happydude wrote:
> crikey... ive been looking at this screen way too long..

For the specific problem, the -1* solution is probably the quickest.

But, just for pedagogical reasons, the more generic way could be

x(x==1) = -1

for cases where a transformation doesn't work. It's "logical
addressing", a very powerful ML implementation.

> how do i delete a post from this thing :)

You don't -- despite the gui interface at TMW, c.s-s-.m is a usenet
group and postings are spread to multitude of servers just to make sure
everybody sees... :)

--

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