Sample fixed number of rows from matrix at random interval within a range?

  • Follow


Hi,

I need help extracting a fixed number of rows from a matrix, at random intervals within a fixed range. I want to create a matrix that is a subsample of my original data matrix. The trick is that I want to select rows at random intervals between 9-19. For example, I would select row numbers

1 (+interval of 9)
10 (+interval of 18)
28 (+ interval of 10)
38 (+ interval of 12)
50 (+ interval of 9)
59 (+ another random interval between 9-19)
....
3000

Here's what I have:

data = Sim10spp  % A 3000x10 data matrix
C = 8+(19-8)*rand(250,1); %creates 250x1 vector "C" of random numbers between 9-19, inclusive
Cround=ceil(C);  %turn random numbers into integers
Random = data(1:Cround:3000,:); %Create new matrix "Random" by selecting rows from "data" at increments given by "Cround".

The problem with this code is that "Random" doesnt have a fixed number of rows; it varies in length, depending on which numbers are in "Cround". I need a matrix of 250 rows only, that samples from the entire 3000 rows of "data", including the first and last rows. So the first row selected for "Random" should be = 1, the last row should be = 3000, and the length of "Random" should be = 250. 

Thanks!
0
Reply Tessa 3/18/2011 8:50:23 PM

On 3/18/2011 1:50 PM, Tessa wrote:
> Hi,
>
> I need help extracting a fixed number of rows from a matrix, at random intervals within a fixed range.

snip.

May be randi() is what you want, not rand()?

--Nasser
0
Reply Nasser 3/18/2011 9:00:20 PM


1 Replies
453 Views

(page loaded in 0.033 seconds)

Similiar Articles:













7/24/2012 9:06:56 PM


Reply: