Sign in

username:

password:



Not a member?

Search matlab



Search tips

Subscribe to matlab



matlab by Keywords

Atanh | Autocorrelation | Bandpass Filter | C++ | Conv | Database | Deconv | Excel | FFT | Filter | Filtering | FIR | Fourier Transfrom | FSK | Gaussian Noise | Haykin | IFFT | Image | Java | LFSR | LMS | LPC | MEX | OFDM | QPSK | Radix | Random | Sampling | Segmentation | Simulink | Visual Basic | Waveform | Wavelet


Discussion Groups

Discussion Groups | Matlab DSP | random rearrangement a vector

Technical discussion about Matlab and issues related to Digital Signal Processing.

  

Post a new Thread

random rearrangement a vector - Emre ARDALI - May 28 8:26:04 2007



Hi everybody;
I want to learn about if it is possible rearrange a vector in MATLAB in a random manner. For
example i have the vector=[1 3 5 8 7 0] and i want a new vector using the vector elements but
different order
i.e. new_vector=[0 7 3 1 8 5 ]; this order sould be random.
Any idea?

I think to use "randint" to regenerate indexes then create new vector using new index
order. But problem is such a random indexing may repeated. Some index may appear more than 1
times and some does not appear.

Do you have any advise?

Thanks 
Regards

Emre



(You need to be a member of matlab -- send a blank email to matlab-subscribe@yahoogroups.com )

Re: random rearrangement a vector - sjoh...@cnbc.cmu.edu - May 29 9:37:24 2007

Emre,
  You can use the randperm function for doing this. RANDPERM(n) is a
random permutation of the integers from 1 to n. So, if you have a vector
,V , get random index vector of V, by assigning,

z = randperm(size(V,2));
new_V = V(z);

So, if V = [1 3 5 8 7 0];
then z= randperm(V) could be [6 5 2 1 4 3], and therefore,
V(z) will be [0 7 3 1 8 5 ];

Remember to repeat both the steps above to generate new random arrangement
everytime. Let me know if this makes sense.
> Hi everybody;
> I want to learn about if it is possible rearrange a vector in MATLAB in a
> random manner. For example i have the vector=[1 3 5 8 7 0] and i want a
> new vector using the vector elements but different order
> i.e. new_vector=[0 7 3 1 8 5 ]; this order sould be random.
> Any idea?
>
> I think to use "randint" to regenerate indexes then create new vector
> using new index order. But problem is such a random indexing may repeated.
> Some index may appear more than 1 times and some does not appear.
>
> Do you have any advise?
>
> Thanks
> Regards
>
> Emre
>



(You need to be a member of matlab -- send a blank email to matlab-subscribe@yahoogroups.com )

Re: random rearrangement a vector - "Sameer S.M" - May 29 9:41:58 2007

Hi Emre,

I think u can use the built in function, "randperm" or "permute". Have a
look at the help for these commands..

bye
sameer

On 5/27/07, Emre ARDALI <e...@yahoo.com> wrote:
>
>   Hi everybody;
> I want to learn about if it is possible rearrange a vector in MATLAB in a
> random manner. For example i have the vector=[1 3 5 8 7 0] and i want a new
> vector using the vector elements but different order
> i.e. new_vector=[0 7 3 1 8 5 ]; this order sould be random.
> Any idea?
>
> I think to use "randint" to regenerate indexes then create new vector
> using new index order. But problem is such a random indexing may repeated.
> Some index may appear more than 1 times and some does not appear.
>
> Do you have any advise?
>
> Thanks
> Regards
>
> Emre
>


(You need to be a member of matlab -- send a blank email to matlab-subscribe@yahoogroups.com )