Path: news.mathworks.com!not-for-mail
From: Peter Perkins <Peter.Perkins@MathRemoveThisWorks.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: randn usage error
Date: Wed, 04 Nov 2009 11:04:10 -0500
Organization: The MathWorks, Inc.
Lines: 15
Message-ID: <hcs8lq$mpi$1@fred.mathworks.com>
References: <hcs392$4ve$1@fred.mathworks.com>
NNTP-Posting-Host: perkinsp.dhcp.mathworks.com
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
X-Trace: fred.mathworks.com 1257350650 23346 172.31.57.88 (4 Nov 2009 16:04:10 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Wed, 4 Nov 2009 16:04:10 +0000 (UTC)
User-Agent: Thunderbird 2.0.0.23 (Windows/20090812)
In-Reply-To: <hcs392$4ve$1@fred.mathworks.com>
Xref: news.mathworks.com comp.soft-sys.matlab:582426


Vijayalayan T.R. wrote:

> randn('state', 2*(i+j));

> And the error is
> ??? Error using ==> randn
> State must be a double scalar or the output of RANDN('state').

As Wayne said, if i and j may be referring to complex values.  But even if you fix that, there may be a bigger issue.  If your intention is that i and j are loop counters, you almost certainly do _not_ want to be reseeding the generator every time though the loop(s).  The only reason for wanting to do that is to ensure a certain kind of reproducability -- so that you can reproduce the results of any given iteration without going through the whole loop.

Take to heart this note in the (current version of the) help:

    Resetting the default stream to the same fixed state allows computations
    to be repeated.  Setting the stream to different states leads to unique
    computations, however, it does not improve any statistical properties.