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?

 採用された回答

James Tursa
James Tursa 2015 年 4 月 24 日
編集済み: James Tursa 2015 年 4 月 24 日

3 投票

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);

3 件のコメント

nurul liyana
nurul liyana 2015 年 4 月 24 日
may i know 2 stand for what? i mean (data_sample,2)
James Tursa
James Tursa 2015 年 4 月 24 日
編集済み: James Tursa 2015 年 4 月 24 日
The 2 stands for the 2nd size value ... i.e., the number of columns. A 1 would have been for rows. E.g.,
>> data_sample = rand(3,5)
data_sample =
0.3063 0.8176 0.3786 0.3507 0.5502
0.5085 0.7948 0.8116 0.9390 0.6225
0.5108 0.6443 0.5328 0.8759 0.5870
>> size(data_sample)
ans =
3 5 % <-- Dimensions are 3 x 5
>> size(data_sample,1)
ans =
3 % <-- 1st dimension is 3
>> size(data_sample,2)
ans =
5 % <-- 2nd dimension is 5
nurul liyana
nurul liyana 2015 年 4 月 24 日
thanks a lot. i really appreciate it

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeCreating and Concatenating Matrices についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by