Divide the matrix randomly, based on columns

2 ビュー (過去 30 日間)
Joana
Joana 2019 年 12 月 11 日
コメント済み: Rik 2019 年 12 月 11 日
Hi
I have a matrix x of size 78000x204. I need to divide it into nonoverlapping but random 70:15:15 percent of the data, based on number of columns.
Any help, how to do that.?

採用された回答

Rik
Rik 2019 年 12 月 11 日
You mean like this?
fractions=[70 15 15];
x=rand(78000,100);%use 100 to show the split is indeed 75:15:15
groups=cell(size(fractions));%pre-allocate output
f=fractions/sum(fractions);
f=[0 cumsum(f)];
r=randperm(size(x,2))/size(x,2);
for n=1:numel(groups)
L= r>f(n) & r<=f(n+1);
groups{n}=x(:,L);
end
  2 件のコメント
Joana
Joana 2019 年 12 月 11 日
Yes, but i'm not sure if it's dividing the data randomly and nonoverlapping.?
I can't figure it out as it's a long data with 78000x204.
Rik
Rik 2019 年 12 月 11 日
Because randperm is generating the indices, this is guaranteed not to result in overlapping groups. Unless there are columns in your data that are equal to eachother, there is not be any match between the groups.

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

その他の回答 (0 件)

カテゴリ

Help Center および 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