MATLAB: How to take a random sample of each column

.m formatrandom number generatorStatistics and Machine Learning Toolbox

I have data from a file with 25 columns and 9000 rows. Actually the problem is that I would like to have everything on an .m format and not on a .mat one but having too many rows, this is not possible (when I try to save the file it is said that the files that are too big will be saved as a .mat). How can I get just a random sample for each column (I mean around 150-200 rows). Thank you.

Best Answer

If you have the Statistics and Machine Learning Toolbox, you can use the randsample() function:
y = randsample(n,k) returns a k-by-1 vector y of values sampled uniformly at random, without replacement, from the integers 1 to n.
y = randsample(population,k) returns a vector of k values sampled uniformly at random, without replacement, from the values in the vector population. The orientation of y (row or column) is the same as population.
y = randsample(n,k,replacement) or y = randsample(population,k,replacement) returns a sample taken with replacement if replacement is true, or without replacement if replacement is false. The default is false.
y = randsample(n,k,true,w) or y = randsample(population,k,true,w) returns a weighted sample taken with replacement, using a vector of positive weights w, whose length is n. The probability that the integer i is selected for an entry of y is w(i)/sum(w). Usually, w is a vector of probabilities. randsample does not support weighted sampling without replacement.
y = randsample(s,...) uses the stream s for random number generation. s is a member of the RandStream class. Default is the MATLABĀ® default random number stream.