how can i randomly sample from a matrix and determine the remaining part?

1 回表示 (過去 30 日間)
EM geo
EM geo 2018 年 11 月 9 日
コメント済み: EM geo 2018 年 11 月 9 日
i have a matrix (D) having 343 rows and 7 columns and i want to sample randomly the 30% of the data and determine the remaining 70% (no randomly). I wrote this code for randomly sample the 30% but i don't know how determine the rest.
perc =30; %percentual
n = round(343*perc/100); % number of rows associated to 30% of data
c=randperm(length(D),n);
D1=D(c,:) %output matrix

採用された回答

Bruno Luong
Bruno Luong 2018 年 11 月 9 日
編集済み: Bruno Luong 2018 年 11 月 9 日
D2=D(setdiff(1:end,c),:)
or
b = ~logical(accumarray(c(:),1,[size(D,1) 1]));
D2 = D(b,:);
or
b = true([size(D,1) 1]);
b(c) = false;
D2 = D(b,:);

その他の回答 (0 件)

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by