Matlab/Octave - fixed length vector of randomly distributed values from another vector

Thread Starter

simozz

Joined Jul 23, 2017
107
Hello,

I am trying to set up a vector of randomly distributed values taken from another vector using Octave (I can use Matlab as well). For example:

Code:
% indexes from 0 to 99
n = 0:4;
z = roots([1 0 0 0 1])
z =

  -0.70711 + 0.70711i
  -0.70711 - 0.70711i
   0.70711 + 0.70711i
   0.70711 - 0.70711i
Now I would like to build a vector of length n with values of z randomly distributed. For example, assuming x will be a vector of length n :

Code:
x = [-0.70711 + 0.70711i    0.70711 - 0.70711i    -0.70711 - 0.70711i    -0.70711 + 0.70711i    0.70711 + 0.70711i ]
What is the function I have to use (if exists) to obtain this kind of result ?
Thank you in advance.
 
Last edited:

Thread Starter

simozz

Joined Jul 23, 2017
107
Possible solution for a 100 elements of vector:

Code:
n = 1:100;
z = roots([1 0 0 0 1]);
% vector of 100 random indexes in the interval (1, 4) since z is a 4 elements vector
nx = randint(1, 100, [1, 4]);
x = z(nx(n))';
:)
 
Last edited:
Top