Path: news.mathworks.com!newsfeed-00.mathworks.com!newsfeed2.dallas1.level3.net!news.level3.com!postnews.google.com!u1g2000pre.googlegroups.com!not-for-mail
From: Engineering <rrengineeringworksldh@gmail.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Changing values in array if they meet certain critria
Date: Thu, 17 Dec 2009 05:21:09 -0800 (PST)
Organization: http://groups.google.com
Lines: 32
Message-ID: <3ffdd56b-95bf-489a-bddb-9be92b7fc37a@u1g2000pre.googlegroups.com>
References: <hgd9c2$et9$1@fred.mathworks.com> <hgdadq$ljn$1@fred.mathworks.com>
NNTP-Posting-Host: 122.173.149.37
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
X-Trace: posting.google.com 1261056069 31253 127.0.0.1 (17 Dec 2009 13:21:09 GMT)
X-Complaints-To: groups-abuse@google.com
NNTP-Posting-Date: Thu, 17 Dec 2009 13:21:09 +0000 (UTC)
Complaints-To: groups-abuse@google.com
Injection-Info: u1g2000pre.googlegroups.com; posting-host=122.173.149.37; 
	posting-account=8iq58AoAAAC4gkfgjYWBjr22dBnry2dU
User-Agent: G2/1.0
X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.1.6) 
	Gecko/20091201 Firefox/3.5.6,gzip(gfe),gzip(gfe)
Xref: news.mathworks.com comp.soft-sys.matlab:593416

On Dec 17, 6:07 pm, "Jos (10584) " <#10...@fileexchange.com> wrote:
> "Ulrik Nash" <u...@sam.sdu.dk> wrote in message <hgd9c2$et...@fred.mathworks.com>...
> > Hi everyone,
>
> > I have an array A with many numbers:
>
> > 12
> > 32
> > 35
> > 45
> > ...
> > nth
>
> > Now I wish to change the numbers in the array, if they meet certain criteria, for example, if they are larger than 30, say. How do I do this without using a for loop?
>
> > Regards,
>
> > Ulrik.
>
> Use one of the powers of matlab: logical indexing
>
> a = [1 12 3 17 2 3 14 21]
> q = a > 10 % a logical vector (true or false)
> a(q) = a(q) + 50
>
> hth
> Jos
Go with this link for answer
http://groups.google.com/group/engineering-works/web/engineering-works