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:
Pick random lines of a matrix ?

Subject: Pick random lines of a matrix ?

From: MOUIZINA Ali

Date: 16 Apr, 2010 17:59:06

Message: 1 of 3

Hello everyone,

I have a matrix called F (size : 152 4) and i would like to pick randomly 53 lines among the 66 first lines and put them in a new matrix X, then i would like to pick randomly 45 lines among the 56 next lines of F and put them in X and finally pick randomly 24 lines of the last 30 lines of F and put them also in X.

So after all these operations, my new matrix X will have 122 lines and 4 rows.
By the way, i can pick only once each line of F so that i don't have the same lines repeated in X.

Thank you very much.

PS:I tried to search on the forum about something similar with no relevant results

Ali

Subject: Pick random lines of a matrix ?

From: Roger Stafford

Date: 16 Apr, 2010 18:39:23

Message: 2 of 3

"MOUIZINA Ali" <faytstrife@hotmail.fr> wrote in message <hqa8ha$89u$1@fred.mathworks.com>...
> Hello everyone,
>
> I have a matrix called F (size : 152 4) and i would like to pick randomly 53 lines among the 66 first lines and put them in a new matrix X, then i would like to pick randomly 45 lines among the 56 next lines of F and put them in X and finally pick randomly 24 lines of the last 30 lines of F and put them also in X.
>
> So after all these operations, my new matrix X will have 122 lines and 4 rows.
> By the way, i can pick only once each line of F so that i don't have the same lines repeated in X.
>
> Thank you very much.
>
> PS:I tried to search on the forum about something similar with no relevant results
>
> Ali

p1 = randperm(66);
p1 = p1(1:53);
p2 = randperm(56)+66;
p2 = p2(1:45);
p3 = randperm(30)+66+56;
p3 = p3(1:24);
X = F([p1,p2,p3],:);

Roger Stafford

Subject: Pick random lines of a matrix ?

From: MOUIZINA Ali

Date: 16 Apr, 2010 18:58:20

Message: 3 of 3

Thank you very much, your code is optimal.

Tags for 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