Random sample and percentage
10 views (last 30 days)
I have a table with several data (columns and rows). I would like to take il 20% or the 10% of the data, but the sample has to be random.
As finally result, I would like the table with the random sample of the 20%.
How can I do?
Yongjian Feng on 6 Jul 2021
column_count = 100; % your columns
row_count = 200; % your rows
percentage_to_take = 0.2; % you take 20% of total
total_count = column_count * row_count; % total count of samples
samples_to_take = percentage_to_take * total_count;
% Use a for loop
sample = zeros(1, saamples_to_take);
c_index = randi(column_count, 1); % a random index into columnn
r_index = randi(row_count, 1); % a random index into row
% access your table
sample(i) = your_table(c_index, r_index);