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:
Selecting subvectors and observations from original data to form samples

Subject: Selecting subvectors and observations from original data to form samples

From: dhaskantha

Date: 24 Apr, 2012 05:39:13

Message: 1 of 8

Hi!

I have a data, y=[379 357 390 376 376; 363 367 382 381 359; 401 402 407 402 396; 402 387 392 395 394; 415 405 396 390 395];
This has 5 rows(5 sub-vectors in my case) and 5 columns. I am supposed to draw 5 sub-vectors WITH REPLACEMENT from the original data vector and then draw 5 observations WITH REPLACEMENT from each sub-vector obtained. This leads to a new sample of size 5x5. Can anybody help me out with this using MATLAB? Am I supposed to use randsample or datasample?
Your help is much appreciated. Thank you.

Regards,
dhaskantha

Subject: Selecting subvectors and observations from original data to form samples

From: Bruno Luong

Date: 24 Apr, 2012 06:07:11

Message: 2 of 8

"dhaskantha" wrote in message <jn5ea1$obe$1@newscl01ah.mathworks.com>...
> Hi!
>
> I have a data, y=[379 357 390 376 376; 363 367 382 381 359; 401 402 407 402 396; 402 387 392 395 394; 415 405 396 390 395];
> This has 5 rows(5 sub-vectors in my case) and 5 columns. I am supposed to draw 5 sub-vectors WITH REPLACEMENT from the original data vector and then draw 5 observations WITH REPLACEMENT from each sub-vector obtained. This leads to a new sample of size 5x5.

r = ceil(5*rand(1,5))
c = ceil(5*rand(1,5))
z = y(r,c);

% Bruno

Subject: Selecting subvectors and observations from original data to form samples

From: Roger Stafford

Date: 24 Apr, 2012 06:15:14

Message: 3 of 8

"dhaskantha" wrote in message <jn5ea1$obe$1@newscl01ah.mathworks.com>...
> Hi!
>
> I have a data, y=[379 357 390 376 376; 363 367 382 381 359; 401 402 407 402 396; 402 387 392 395 394; 415 405 396 390 395];
> This has 5 rows(5 sub-vectors in my case) and 5 columns. I am supposed to draw 5 sub-vectors WITH REPLACEMENT from the original data vector and then draw 5 observations WITH REPLACEMENT from each sub-vector obtained. This leads to a new sample of size 5x5. Can anybody help me out with this using MATLAB? Am I supposed to use randsample or datasample?
> Your help is much appreciated. Thank you.
>
> Regards,
> dhaskantha
- - - - - - - - -
 p = ceil(5*rand(1,5));
 z = y(p,:);
 q = bsxfun(@plus,[1:5].',5*floor(5*rand(5,5)));
 z = reshape(z(q),5,5);

Roger Stafford

Subject: Selecting subvectors and observations from original data to form samples

From: Bruno Luong

Date: 24 Apr, 2012 06:43:25

Message: 4 of 8

Obviously I and Roger read differently the problem:

- to me the observation-draw is the same for all sub-vectors,
- to Roger the observation-draw are different for each sub-vector.

Up to you to choose what you need.

Bruno

Subject: Selecting subvectors and observations from original data to form samples

From: dhaskantha

Date: 24 Apr, 2012 09:58:06

Message: 5 of 8

Many thanks Bruno and Roger. I will try this out.

Regards,
dhaskantha

Subject: Selecting subvectors and observations from original data to form samples

From: dhaskantha

Date: 25 Apr, 2012 06:06:07

Message: 6 of 8

Hi!

I am able to generate one sample with the way you proposed. I am supposed to generate N samples like z from the original data y. How do I use the loop to do it? Is there a better way for me to do so? Thank you.

Regards,
dhaskantha

> - - - - - - - - -
> p = ceil(5*rand(1,5));
> z = y(p,:);
> q = bsxfun(@plus,[1:5].',5*floor(5*rand(5,5)));
> z = reshape(z(q),5,5);
>
> Roger Stafford

Subject: Selecting subvectors and observations from original data to form samples

From: Roger Stafford

Date: 25 Apr, 2012 20:30:22

Message: 7 of 8

"dhaskantha" wrote in message <jn848f$j9h$1@newscl01ah.mathworks.com>...
> I am able to generate one sample with the way you proposed. I am supposed to generate N samples like z from the original data y.
- - - - - - - - - -
 p = bsxfun(@plus,ceil(5*rand(5,1,N)),5*floor(5*rand(5,5,N)));
 z = reshape(y(p),5,5,N);

This should generate a three-dimensional array z of size 5 x 5 x N with elements from y. Each of the slices z(:,:,k) from k = 1 to k = N should be a valid "sample" from y in accordance with the random selection procedure you described.

  (This assumes that my interpretation of what you wrote is correct. Bruno had a different interpretation of your words, so you should decide which is the one you want to use.)

Roger Stafford

Subject: Selecting subvectors and observations from original data to form samples

From: dhaskantha

Date: 26 Apr, 2012 01:55:26

Message: 8 of 8

Hi Roger!

Thank you for your help. Will try working out using this method.

Regards,
dhaskantha


"Roger Stafford" wrote in message <jn9msu$nri$1@newscl01ah.mathworks.com>...
> "dhaskantha" wrote in message <jn848f$j9h$1@newscl01ah.mathworks.com>...
> > I am able to generate one sample with the way you proposed. I am supposed to generate N samples like z from the original data y.
> - - - - - - - - - -
> p = bsxfun(@plus,ceil(5*rand(5,1,N)),5*floor(5*rand(5,5,N)));
> z = reshape(y(p),5,5,N);
>
> This should generate a three-dimensional array z of size 5 x 5 x N with elements from y. Each of the slices z(:,:,k) from k = 1 to k = N should be a valid "sample" from y in accordance with the random selection procedure you described.
>
> (This assumes that my interpretation of what you wrote is correct. Bruno had a different interpretation of your words, so you should decide which is the one you want to use.)
>
> Roger Stafford

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