MATLAB: How to select random columns

columnrandom

i have a data sample named data. it contains 4601 rows with 57 column.and how can i generate random columns from the data sample?

Best Answer

If you want only one column at random:
x = randi(size(data_sample,2));
column = data_sample(:,x);
For more than one column (may have repeats):
ncol = number of columns you want
x = randi(size(data_sample,2),1,ncol);
columns = data_sample(:,x);
For more than one column with no repeats (will error if ncol is too large):
ncol = number of columns you want
x = randperm(size(data_sample,2),ncol);
columns = data_sample(:,x);