Generate a vector of predetermined numbers

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Generate a vector of predetermined numbers

simia
I simply have to generate in Octave a 1xn vector of predetermined numbers. I have to generate a 1xn random sequence of 0.7 and 1.8.
How can I do it? Thanks
Reply | Threaded
Open this post in threaded view
|

Re: Generate a vector of predetermined numbers

Bård Skaflestad
On Sun, 2013-07-07 at 02:20 -0700, simia wrote:
> I simply have to generate in Octave a 1xn vector of predetermined
>  numbers. I have to generate a 1xn random sequence of 0.7 and 1.8.

I don't quite understand what you want.  Do you want a sequence
containing *only* the numbers 0.7 and 1.8 or do you want a sequence
drawn from the interval [0.7, 1.8]?

In the first case, I suggest doing something like this:

        vals = [ 0.7, 1.8 ];
        seq  = vals(ceil(2 * rand([1, n])));

In the second, you could probably get away with

        vals = [ 0.7, 1.8 ];
        seq  = vals(1) + diff(vals)*rand([1, n]);

Of course, the *applicability* of either of these suggestions depends (a
lot) on the statistical properties needed in your application.


Sincerely,
--
Bård Skaflestad <[hidden email]>
SINTEF ICT, Applied Mathematics

_______________________________________________
Help-octave mailing list
[hidden email]
https://mailman.cae.wisc.edu/listinfo/help-octave