From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: "not a number" message
Date: Sat, 3 Jan 2009 07:09:07 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 37
Message-ID: <gjn2uj$cb9$>
References: <gjmk9m$5ke$> <gjmogm$evm$> <gjmpvh$6hd$>
Reply-To: <HIDDEN>
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: 1230966547 12649 (3 Jan 2009 07:09:07 GMT)
NNTP-Posting-Date: Sat, 3 Jan 2009 07:09:07 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1187260
Xref: comp.soft-sys.matlab:509614

"Nick Stucky-Mack" <> wrote in message <gjmpvh$6hd$>...
> Alright, thanks Roger!  I've included the entirety of the code here.  
> .......

A few comments, Nick:

  I notice that in your first trip on each run through the


loop, every column except one in 'abundance' is initially all zeros, and yet you divide by the sum of one of these columns in

 relAbundTwo = ....

If 'chosenMutantN' is anything but 1 at this point you could be in for trouble from the resultant infinity.  One of the ways a NaN is produced is by dividing an infinity by another infinity or by subtracting two infinities.  Another way is zero divided by zero.

  There is a division by 'total' which could be zero that first trip since it comes from an element of 'abundance'

 total = abundance(chosenMutantA,chosenMutantN)*...

and when you then calculate 'birth' you have a sure-fire NaN from the zero divided by zero situation there.

  It would be wise to make use of your debugger facilities to catch stuff like this yourself as it happens so you can analyze it for errors or unwise coding.  After all, if you are going to be an effective programmer, it is absolutely essential to know how to debug your own code.  No-one else can do as good a job as you yourself.  I speak from long experience.

  You need much more robust code that is protected against certain kinds of unplanned consequences.  For example in 

  chosenMutantN = j + 1;
  j = j + 1;

you have no guard against j going beyond the end of the 'relAbundOne' array limit in case all its values are too small.

Roger Stafford