```Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Applying equation to Matrix
Date: Sun, 22 Aug 2010 18:04:06 +0000 (UTC)
Organization: The MathWorks Inc
Lines: 28
Message-ID: <i4roqm\$rqs\$1@fred.mathworks.com>
References: <i4rm8j\$gd7\$1@fred.mathworks.com>
NNTP-Posting-Host: webapp-05-blr.mathworks.com
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1282500246 28508 172.30.248.35 (22 Aug 2010 18:04:06 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Sun, 22 Aug 2010 18:04:06 +0000 (UTC)
Xref: news.mathworks.com comp.soft-sys.matlab:664090

"Fred O'Con" <barabus12@hotmail.com> wrote in message <i4rm8j\$gd7\$1@fred.mathworks.com>...
> I want to apply equation to a matrices elements individualy.
> ie if  any element in C is less than 50 i want it to change element to 0
> If it is greater than 50 but less than 600 i want it to apply the equation below to the element
> and less than 1100 and greater than 600 apply the last equation to the element
>
> ie working its way through the matrix
>
> if 0<C<50;
> C=0;
> elseif 600>C>=50;
> C=(.2666*C+155.29);
> elseif 1100>C>=600;
> C=(.4041*C+106.8);
> else
> C=C
> end

Hi Fred, There are many ways to do this. One way is to use logical indexing.

C = randi(1300,20,20);
C(C<50) = 0;
% I use > 0 here because you've already set everything less than 50 to zero
C(C>0 & C<600) = 0.2666*C(C>0 & C<600)+155.29;

And so on.

Wayne
```