Path: news.mathworks.com!not-for-mail
From: "Jan Simon" <matlab.THIS_YEAR@nMINUSsimon.de>
Newsgroups: comp.soft-sys.matlab
Subject: Re: How to make the output always be between 0 and 1
Date: Thu, 24 Jun 2010 10:21:05 +0000 (UTC)
Organization: Universit&#228;t Heidelberg
Lines: 17
Message-ID: <hvvbih$p2c$1@fred.mathworks.com>
References: <hvulnk$4uf$1@fred.mathworks.com> <hvv7dt$s0m$1@fred.mathworks.com>
Reply-To: "Jan Simon" <matlab.THIS_YEAR@nMINUSsimon.de>
NNTP-Posting-Host: webapp-02-blr.mathworks.com
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1277374865 25676 172.30.248.37 (24 Jun 2010 10:21:05 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Thu, 24 Jun 2010 10:21:05 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 869888
Xref: news.mathworks.com comp.soft-sys.matlab:647670

Dear dhaskantha,

> for i=1:n
> x(i)=normrnd(0,1);
> end
> 
> where I only want the values of x(i), say between 0 and 1. How do I do it?

Between 0 and 1:
  x = min(0, max(1, anyFunction))
0 or 1:
  x = double(anyFunction  > 0.5);
Obviously "0.5" is just an example and "anyFunction" depends on your needs.
anyFunction can reply (or be) an array also, which is usually faster than using a FOR loop for elementwise processing.
Care about NaNs, on demand.

Good luck, Jan