Path: news.mathworks.com!newsfeed-00.mathworks.com!news.tele.dk!feed118.news.tele.dk!news.tele.dk!small.news.tele.dk!newsgate.cistron.nl!newsgate.news.xs4all.nl!news2.euro.net!feeder.news-service.com!aioe.org!.POSTED!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Finding 0's and setting to 1
Date: Sat, 03 Sep 2011 07:05:54 -0700
Organization: Aioe.org NNTP Server
Lines: 46
Message-ID: <j3tc96$d84$1@speranza.aioe.org>
References: <j3t1sm$dtk$1@newscl01ah.mathworks.com> <j3t66h$tjg$1@speranza.aioe.org> <j3t71p$rl6$1@newscl01ah.mathworks.com> <j3taqg$8cq$1@speranza.aioe.org>
Reply-To: <HIDDEN>
NNTP-Posting-Host: 4IuMaYl5j9Y5F74I990LJw.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 NT 6.1; WOW64; rv:6.0.1) Gecko/20110830 Thunderbird/6.0.1
X-Notice: Filtered by postfilter v. 0.8.2
Xref: news.mathworks.com comp.soft-sys.matlab:742137

On 9/3/2011 6:41 AM, dpb wrote:
> On 9/3/2011 7:37 AM, Ulrik Nash wrote:
>> "Nasser M. Abbasi"<nma@12000.org>  wrote in message
>> <j3t66h$tjg$1@speranza.aioe.org>...
>>> On 9/3/2011 4:09 AM, Ulrik Nash wrote:
>>>> Hi Everyone,
>>>>
>>>> Suppose I have a vector A:
>>>>
>>>> A = [1 0 0 1]
>>>>
>>>> and if wish to set all 0's in A to 1 to create B:
>>>>
>>>> B = [1 1 1 1]
>>>>
>>>> How can I do this?
>>>>
>>>> Regards,
>>>>
>>>> Ulrik.
>>>
>>> EDU>>  A(A==0)=1
>>>
>>
>> Thank you both, so simple...
>>
>>> A =
>>>
>>> 1 1 1 1
>
> For the actual problem as given
>
> B=ones(size(A));
>
> is possibly quicker for large A eliminating the logical.
>
> --

yes ofcourse, but I assumed there might be other values in there besides
'1' and '0' when OP said "wish to set all 0's in A to 1".

But now you mention it, if all was needed is a vector of one's, then
your solution is the right one ofcourse.

--Nasser