Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Random row indexing

Subject: Random row indexing

From: doug kopet

Date: 17 Aug, 2010 02:52:04

Message: 1 of 4

Hi everyone,
I would like some help .I have a problem with random indexing. Below is everything I have so far.

%=================================================
clc;
clear all;

RR = [-1.9853 -2.8594 -2.5919 -0.12209;
                   -5.4278 -2.1993 -2.9297 -2.6783;
                     2.309 -2.1135 -0.42238 -0.33848;
                   -2.9826 -1.3475 -4.8597 0.10409;
               -0.074397 -1.2967 -1.6668 -0.21436]


  random_index = ceil(rand(5,1)*size(RR,2))

  Y= RR(random_index,:)
%==================================================

My problem is:

1) my "random_index" matrix generates random values that are repeated ,which I want to get rid off. I only want to randomize the values so the index values are not repeated at all.

for example ,if I run the above code I get the following for "random_index" :

random_index =

     1
     3
     2
     2
     4

the digit '2' is repeated which I don't want , I want the answer to be randomly populated with values 1 to 5 present only once.

for example, I want a answer such as:

random_index =

     4
     5
     2
     3
     1

Any help welcome.
dougy

Subject: Random row indexing

From: Walter Roberson

Date: 17 Aug, 2010 03:00:08

Message: 2 of 4

doug kopet wrote:

> 1) my "random_index" matrix generates random values that are repeated
> ,which I want to get rid off. I only want to randomize the values so the
> index values are not repeated at all.

randperm(5)

Subject: Random row indexing

From: Roger Stafford

Date: 17 Aug, 2010 03:03:04

Message: 3 of 4

"doug kopet" <onedougk@gmail.com> wrote in message <i4ctgk$g6p$1@fred.mathworks.com>...
> Hi everyone,
> I would like some help .I have a problem with random indexing. Below is everything I have so far.
>
> %=================================================
> clc;
> clear all;
>
> RR = [-1.9853 -2.8594 -2.5919 -0.12209;
> -5.4278 -2.1993 -2.9297 -2.6783;
> 2.309 -2.1135 -0.42238 -0.33848;
> -2.9826 -1.3475 -4.8597 0.10409;
> -0.074397 -1.2967 -1.6668 -0.21436]
>
>
> random_index = ceil(rand(5,1)*size(RR,2))
>
> Y= RR(random_index,:)
> %==================================================
>
> My problem is:
>
> 1) my "random_index" matrix generates random values that are repeated ,which I want to get rid off. I only want to randomize the values so the index values are not repeated at all.
>
> for example ,if I run the above code I get the following for "random_index" :
>
> random_index =
>
> 1
> 3
> 2
> 2
> 4
>
> the digit '2' is repeated which I don't want , I want the answer to be randomly populated with values 1 to 5 present only once.
>
> for example, I want a answer such as:
>
> random_index =
>
> 4
> 5
> 2
> 3
> 1
>
> Any help welcome.
> dougy
- - - - - - - - -
  Use randperm.

Roger Stafford

Subject: Random row indexing

From: doug kopet

Date: 17 Aug, 2010 03:15:08

Message: 4 of 4

thank you

Tags for this Thread

No tags are associated with this thread.

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.

Contact us