how to select random columns?
조회 수: 4 (최근 30일)
이전 댓글 표시
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?
댓글 수: 0
채택된 답변
James Tursa
2015년 4월 24일
편집: James Tursa
2015년 4월 24일
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
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
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!