Can I randomly sample from a csv file?

2 ビュー (過去 30 日間)
Sarah E
Sarah E 2014 年 8 月 21 日
回答済み: Image Analyst 2014 年 8 月 21 日
Hi, I have a .csv file of 1000000 values, I want to randomly sample x amount of values from this without repetition. is this possible and how would I do it? It seems the randsample function does not work in this way.

回答 (1 件)

Image Analyst
Image Analyst 2014 年 8 月 21 日
Read the matrix into a variable with csvread(). Then get random samples with randperm():
myData = csvread(filename);
numberToGet = 1000; % or whatever number you want.
randomLocations = randperm(numel(myData), numberToGet)
randomlySelectedValues = myData(randomLocations); % Uses linear indexing into a 2D matrix.

カテゴリ

Help Center および File ExchangeDescriptive Statistics についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by