Thanks for the suggestion. I am still struggling to understand why my vector
is not a valid probability vector though. I don't spot any strange features in
the PROB vector that yields NaN values. Is the fact that some probabilities are
equal a problem? Or that there are some probabilities that are zero?
I hope someone can help me through this. I feel I am missing something
simple.
Thanks,
Erida
Peter Perkins <Peter.PerkinsRemoveThis@mathworks.com> wrote in message
<g3gbuf$1op$1@fred.mathworks.com>...
> Erida Gjini wrote:
> > Hi,
> > I am trying to use the multinomial random variable function
> > in Matlab.
> >
> > PROB=v'/sum(v); % row vector
> > num_events=mnrnd(1,PROB);
> >
> > Sometimes the simulation gives a correct sequence of zeros
> > and a single 1, as I expect. Sometimes though, I get all
> > NaN values in the num_events. I checked my PROB variable and
> > it works fine. It satisfies the condition that it is always
> > between zero and 1. PROB is calculated anew each time, so it
> > decreases in dimension, but I don't store it anywhere. It is
> > overwritten. Any ideas?
>
> Just because v sums to 1 does not mean that it is a valid probability vector.
> You can diagnose this by using an example of an input vector for which
MNRND
> returns NaNs, and stepping through the code in the debugger. If you
cannot find
> such an example, make a local copy of MNRND, with this at the end:
>
> if (any(isnan(r))
> p
> end
>
> and set a breakpoint at the line that displays p, and run your simulation.
When
> the debugger stops at that line, look at p.
>
> Hope this helps.
