Thread Subject: Randomization_same number

Subject: Randomization_same number

From: Kostas

Date: 6 Nov, 2009 21:26:02

Message: 1 of 6

Hi all,

I am trying to present 4 different numbers 120 times in a vector, in a randomized order. But the thing is that I try to avoid repeating the same number twice in a row, and in the same time to keep the repetition frequency of each number the same (= 30).

Do you have any ideas?

Thanks

Subject: Randomization_same number

From: Luigi Giaccari

Date: 6 Nov, 2009 21:58:02

Message: 2 of 6

"Kostas " <eclipse_dsotm@hotmail.com> wrote in message <hd249a$im2$1@fred.mathworks.com>...
> Hi all,
>
> I am trying to present 4 different numbers 120 times in a vector, in a randomized order. But the thing is that I try to avoid repeating the same number twice in a row, and in the same time to keep the repetition frequency of each number the same (= 30).
>
> Do you have any ideas?
>
> Thanks

BUild the 120 element vector in a sorted order than use "randperm"

The "randperm" will help you, but you need to postprocess the data to change duplicate values on a single row. A swap should be good.

http://www.advancedmcode.org/

Subject: Randomization_same number

From: Kostas

Date: 6 Nov, 2009 22:10:03

Message: 3 of 6

>BUild the 120 element vector in a sorted order than use "randperm"
>
>The "randperm" will help you, but you need to postprocess the data to change duplicate >values on a single row. A swap should be good.
>
>http://www.advancedmcode.org/


Thanks for your reply. I think I should have mentioned that I must generate this vector a lot of times in the future, so it must me always different. :)

Thanks again

Subject: Randomization_same number

From: John D'Errico

Date: 6 Nov, 2009 23:04:01

Message: 4 of 6

"Kostas " <eclipse_dsotm@hotmail.com> wrote in message <hd26rr$q78$1@fred.mathworks.com>...
> >BUild the 120 element vector in a sorted order than use "randperm"
> >
> >The "randperm" will help you, but you need to postprocess the data to change duplicate >values on a single row. A swap should be good.
> >
> >http://www.advancedmcode.org/
>
>
> Thanks for your reply. I think I should have mentioned that I must generate this vector a lot of times in the future, so it must me always different. :)
>
> Thanks again

So? Then be efficient in your code. Randperm is
fast. It takes little effort to test to see if elements
are consecutive. Use diff to do the test.

John

Subject: Randomization_same number

From: D

Date: 6 Nov, 2009 23:48:01

Message: 5 of 6

> So? Then be efficient in your code. Randperm is
> fast. It takes little effort to test to see if elements
> are consecutive. Use diff to do the test.
>
> John

Thanks John. I do use the randperm function, but of course i have same trials in a row. I can find where (using diff as well), but still cannot solve the problem.

I created a mask to get rid of all the numbers i've used, but i am not sure if it is efficient and worth trying -i am new in matlab. And besides, it doesn't work properly.

Thanks

Subject: Randomization_same number

From: John D'Errico

Date: 7 Nov, 2009 01:30:07

Message: 6 of 6

"D " <eclipse_dsotm@hotmail.com> wrote in message <hd2cjh$evv$1@fred.mathworks.com>...
> > So? Then be efficient in your code. Randperm is
> > fast. It takes little effort to test to see if elements
> > are consecutive. Use diff to do the test.
> >
> > John
>
> Thanks John. I do use the randperm function, but of course i have same trials in a row. I can find where (using diff as well), but still cannot solve the problem.
>
> I created a mask to get rid of all the numbers i've used, but i am not sure if it is efficient and worth trying -i am new in matlab. And besides, it doesn't work properly.
>
> Thanks

So use randperm. Then set up a loop. Scan through
the sequence. If the ith element is equal to the previous
element, then swap it with the next element in the
sequence which is not equal to it. Continue this
operation until done. If you get to the end without
success, then wrap around to the beginning.

This will be fast.

John

Tags for this Thread

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

rssFeed for this Thread
 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com