Path: news.mathworks.com!newsfeed-00.mathworks.com!news.kjsl.com!feeder.erje.net!eu.feeder.erje.net!newsfeed.datemas.de!rt.uk.eu.org!aioe.org!.POSTED!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: find function
Date: Tue, 02 Jul 2013 08:15:30 -0500
Organization: Aioe.org NNTP Server
Lines: 36
Message-ID: <kqujo9$e63$1@speranza.aioe.org>
References: <kquama$1tf$1@newscl01ah.mathworks.com> <kqucm2$63p$1@newscl01ah.mathworks.com> <kqugpb$fe4$1@newscl01ah.mathworks.com>
NNTP-Posting-Host: 6z92ouJs6jUrQzBaNtLMgA.user.speranza.aioe.org
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
X-Complaints-To: abuse@aioe.org
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.28) Gecko/20120306 Thunderbird/3.1.20
X-Notice: Filtered by postfilter v. 0.8.2
Xref: news.mathworks.com comp.soft-sys.matlab:798681

On 7/2/2013 7:24 AM, Wanderson wrote:
> "Torsten" wrote in message <kqucm2$63p$1@newscl01ah.mathworks.com>...
>> "Wanderson " <wanderson.ferreira@usp.br> wrote in message
>> <kquama$1tf$1@newscl01ah.mathworks.com>...
...

>> > > ... I have a matrix 'A' bellow and I want to know all the
>> positions where the value of 'A' is smaller than 3.
...
>> > > Now, I need to create a new matrix called SOL, the same size as A
>> and within the position where A<3 I need to store the value 1;
>> > > I thought that this following code could work, but didn't work.
>> > > SOL = zeros(3);
>> > SOL(rows,col) = 1;
>> > > > Thanks for the help.
>>
>> Try
>> SOL=zeros(3,3);
>>
...

> I already figure out how to do that. Must be better ways but..
>
> h = find(A<3);
> SOL = zeros(3);
> SOL = SOL(:);
> SOL(h) = 1;
>
> SOL = repmat(SOL,3,3);

Use the logical address array directly instead of FIND

SOL=zeros(size(A));   % to get target desired size/shape
SOL(A<3) = 1;         % set the desired values

--