Thread Subject: randperm

Subject: randperm

From: ching l

Date: 26 Jul, 2008 19:35:03

Message: 1 of 10

a= randperm(6)

I want the "a" to have different number each time, between
1 to 6. However, by using randperm, it called out all the 6
random numbers at a time, which become a= 1 4 6 2 3 5

How do I have different random "a" each time?

for example,

a= 1

a= 3

a= 5

instead of a= 1 4 2 6 3 5



Subject: randperm

From: matt dash

Date: 26 Jul, 2008 20:14:02

Message: 2 of 10

"ching l" <chinglnc@hotmail.com> wrote in message
<g6fu97$7ru$1@fred.mathworks.com>...
> a= randperm(6)
>
> I want the "a" to have different number each time, between
> 1 to 6. However, by using randperm, it called out all the 6
> random numbers at a time, which become a= 1 4 6 2 3 5
>
> How do I have different random "a" each time?
>
> for example,
>
> a= 1
>
> a= 3
>
> a= 5
>
> instead of a= 1 4 2 6 3 5
>
>
>



a=ceil(6*rand)

Subject: randperm

From: ching l

Date: 26 Jul, 2008 20:33:07

Message: 3 of 10

"matt dash" <n.a@mail.com> wrote in message
<g6g0ia$vp$1@fred.mathworks.com>...
> "ching l" <chinglnc@hotmail.com> wrote in message
> <g6fu97$7ru$1@fred.mathworks.com>...
> > a= randperm(6)
> >
> > I want the "a" to have different number each time, between
> > 1 to 6. However, by using randperm, it called out all the 6
> > random numbers at a time, which become a= 1 4 6 2 3 5
> >
> > How do I have different random "a" each time?
> >
> > for example,
> >
> > a= 1
> >
> > a= 3
> >
> > a= 5
> >
> > instead of a= 1 4 2 6 3 5
> >
> >
> >
>
>
>
> a=ceil(6*rand)

but it's going to repeat some time....

I don't want it to repeat, I want to have random number from
1 to 6, for six time, and no repeat number.

is that possible?


Subject: randperm

From: Bruno Luong

Date: 27 Jul, 2008 09:04:09

Message: 4 of 10

"ching l" <chinglnc@hotmail.com> wrote in message
<g6g1m3$cec$1@fred.mathworks.com>...
> I want to have random number from
> 1 to 6, for six time, and no repeat number.
>

And what do you get with one call of randperm(6)? Can you
try to describe it in words and see how it fits with what
you wrote above.

Bruno

Subject: randperm

From: ching l

Date: 27 Jul, 2008 12:40:39

Message: 5 of 10

"Bruno Luong" <b.luong@fogale.findmycountry> wrote in
message <g6hdm9$j18$1@fred.mathworks.com>...
> "ching l" <chinglnc@hotmail.com> wrote in message
> <g6g1m3$cec$1@fred.mathworks.com>...
> > I want to have random number from
> > 1 to 6, for six time, and no repeat number.
> >
>
> And what do you get with one call of randperm(6)? Can you
> try to describe it in words and see how it fits with what
> you wrote above.
>
> Bruno

I have six audio files,

sample{1}= wavread('audio1.wav');
sample{2}= wavread('audio2.wav');
sample{3}= wavread('audio3.wav');
sample{4}= wavread('audio4.wav');
sample{5}= wavread('audio5.wav');
sample{6}= wavread('audio6.wav');

wavplay= sample(round{random number});

so, when I call the wavplay everytime, it should play
different audio each time.

but randperm(6) = (3 4 5 1 2 6);

possible to work around with that?







Subject: randperm

From: Bruno Luong

Date: 27 Jul, 2008 12:56:07

Message: 6 of 10

"ching l" <chinglnc@hotmail.com> wrote in message
<g6hqc7$gck$1@fred.mathworks.com>...

>
> so, when I call the wavplay everytime, it should play
> different audio each time.
>
> but randperm(6) = (3 4 5 1 2 6);
>
> possible to work around with that?

Work around of what problem ?
Just playing track #3, then 4, 5, 1, 2, and then 6 according
to randperm result. Wasn't that a six number randomly chosen
and never repeated? Isn't that what you asked for???

Bruno

Subject: randperm

From: ching l

Date: 27 Jul, 2008 13:58:02

Message: 7 of 10

"Bruno Luong" <b.luong@fogale.findmycountry> wrote in
message <g6hr97$sq6$1@fred.mathworks.com>...
> "ching l" <chinglnc@hotmail.com> wrote in message
> <g6hqc7$gck$1@fred.mathworks.com>...
>
> >
> > so, when I call the wavplay everytime, it should play
> > different audio each time.
> >
> > but randperm(6) = (3 4 5 1 2 6);
> >
> > possible to work around with that?
>
> Work around of what problem ?
> Just playing track #3, then 4, 5, 1, 2, and then 6 according
> to randperm result. Wasn't that a six number randomly chosen
> and never repeated? Isn't that what you asked for???
>
> Bruno

The error- Too many input arguments.

wavplay (sample{randperm(6)});

because it's using six random numbers at a time.
I only want it to play one random number at a time.
That means, whenever I call the wavplay function, it will
randomly choose from 1 to 6, and when I call that function
again, it will choose from 1 to 6, but not the same number
that used before that.






Subject: randperm

From: Bruno Luong

Date: 27 Jul, 2008 14:27:02

Message: 8 of 10

"ching l" <chinglnc@hotmail.com> wrote in message
<g6huta$4pa$1@fred.mathworks.com>...

>
> The error- Too many input arguments.
>
> wavplay (sample{randperm(6)});
>
> because it's using six random numbers at a time.
> I only want it to play one random number at a time.
> That means, whenever I call the wavplay function, it will
> randomly choose from 1 to 6, and when I call that function
> again, it will choose from 1 to 6, but not the same number
> that used before that.
>

The problem is not randperm.

The problem is you call functions that have output and input
but without making sure the compatible between the number of
output/input arguments, their type, etc. In the case
"waveplay", it accepts only ONE argument, whereas when you
the expression:

sample{randperm(6)}

provides a list of SIX elements (MATLAB official term is
"Comma separate list"). This is not allowed by waveplay.

This is a typically problem of syntax. That is why people in
this newsgroup encourage you do debug yourself and
understand deeply MATLAB syntax, type, variable, workspace,
etc... before asking question about rand and randperm.

I suggest you to slow down and doing simple things with
MATLAB syntax. You don't need randperm to see what is wrong.
You should bump to the same error by doing the following:

waveplay(sample{[1 2]})

As long as you don't fully understand what is wrong with
this syntax, you would hardly make any progress in
programming with MATLAB.

Bruno

Subject: randperm

From: ching l

Date: 27 Jul, 2008 14:55:03

Message: 9 of 10

"Bruno Luong" <b.luong@fogale.findmycountry> wrote in
message <g6i0jm$kqb$1@fred.mathworks.com>...
> "ching l" <chinglnc@hotmail.com> wrote in message
> <g6huta$4pa$1@fred.mathworks.com>...
>
> >
> > The error- Too many input arguments.
> >
> > wavplay (sample{randperm(6)});
> >
> > because it's using six random numbers at a time.
> > I only want it to play one random number at a time.
> > That means, whenever I call the wavplay function, it will
> > randomly choose from 1 to 6, and when I call that function
> > again, it will choose from 1 to 6, but not the same number
> > that used before that.
> >
>
> The problem is not randperm.
>
> The problem is you call functions that have output and input
> but without making sure the compatible between the number of
> output/input arguments, their type, etc. In the case
> "waveplay", it accepts only ONE argument, whereas when you
> the expression:
>
> sample{randperm(6)}
>
> provides a list of SIX elements (MATLAB official term is
> "Comma separate list"). This is not allowed by waveplay.
>
> This is a typically problem of syntax. That is why people in
> this newsgroup encourage you do debug yourself and
> understand deeply MATLAB syntax, type, variable, workspace,
> etc... before asking question about rand and randperm.
>
> I suggest you to slow down and doing simple things with
> MATLAB syntax. You don't need randperm to see what is wrong.
> You should bump to the same error by doing the following:
>
> waveplay(sample{[1 2]})
>
> As long as you don't fully understand what is wrong with
> this syntax, you would hardly make any progress in
> programming with MATLAB.
>
> Bruno

yeah, I know about this problem. That's what I said, I'm not
sure how to use randperm in wavplay in this case, because it
has more than one argument. And I can't use rand because I
can't fix the random argument.


Basically, I want the flexibility in randperm (which I can
fix the array for the random), but I want the function in
rand which it only output one arguement at a time.

I'm thinking of a way of to save the randperm(n) into a
column matrix and use it one by one controled by the
program. Then use a counter(a variable) to count which
random number is using. Then regenerate after the counter =
n and reset the counter.

Is this way make sense?





Subject: randperm

From: Bruno Luong

Date: 27 Jul, 2008 15:48:02

Message: 10 of 10

"ching l" <chinglnc@hotmail.com> wrote in message
<g6i287$82n$1@fred.mathworks.com>...

>
> I'm thinking of a way of to save the randperm(n) into a
> column matrix and use it one by one controled by the
> program. Then use a counter(a variable) to count which
> random number is using. Then regenerate after the counter =
> n and reset the counter.
>
> Is this way make sense?
>

Yes it makes more sense. You can even put the counter inside
a wrapper function using PERSISTENT variable and let it roll
automatically. But don't disperse. Try with your idea first,
I think it's good.

Bruno

Tags for this Thread

Everyone's Tags:

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.

Tag Activity for This Thread
Tag Applied By Date/Time
randperm ching l 26 Jul, 2008 15:40:04
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