Interview Question: Random Sampling in Matlab

Sample Question #155 (programming – Matlab)

I give you a dataset with 5 million observations. Write Matlab code that picks a random sub-sample of 1,000 observations from the dataset.

(Comment: Matlab, originally designed for applied math and engineering numerical problems, is very popular in Wall Street quant shops, due to its great handling of vectors and matrices)

Advertisements
This entry was posted in Sample Qs. Bookmark the permalink.

One Response to Interview Question: Random Sampling in Matlab

  1. Brett says:

    ANSWER
     
    The key to getting this question "right" is to realize that it’s very easy to do this in Matlab, and you must not use a loop statement! Just first create a vector of 1,000 random numbers in the range [1, 5000000] and then cross-product this vector with the original dataset’s index vector. Voila!
     

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s