Help using normrnd() to undersample according to the gaussian distribution

1 view (last 30 days)
I have a matrix which is 2000 by 3 and I would like to select 1000 rows of my matrix according to the gaussian distibution however, I am not sure how to go about this. I have thought to use R = normrnd(mu, sigma, k,1)
where k = 1000
I am assuming that mu = 1 and sigma = 1/2000
and then use these numbers to determine the indicies of my new matrix ie
NEWMATRIX = OLDMATRIX(R,:)
However, when I try and execute this code I get the following error message;
Subscript indices must either be real positive integers or logicals.
Any ideas what I may be doing wrong?

Answers (1)

Image Analyst
Image Analyst on 9 Apr 2013
First of all, you need to cast R to be int32 because it's floating point. You can't have the 42.123'th row of a matrix (unless you want to do interpolation).
Next, you'll need to get more than 1000 rows to account for repeats. What if you get row 42 (after rounding) 2 or 3 times? It would only get transferred once. So you'll have to call unique() to pull out only unique rows. You may want to ask for 2000 numbers just to make sure you can always extract 1000 unique numbers.
I can't do it for you because I don't have whatever toolbox normrnd() is in (please enter that into the products list above.)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!