Split a table in two different tables
2 ビュー (過去 30 日間)
古いコメントを表示
Rachele Franceschini
2021 年 9 月 1 日
コメント済み: Walter Roberson
2021 年 9 月 1 日
Hi, Can You help me?
I have a table C. I would like to split in 2 tables. In table 1 there is 30% of the data (chosen randomly) and in the second table there is the 70% of the data.
Do you have a tips?
0 件のコメント
採用された回答
Walter Roberson
2021 年 9 月 1 日
In the case that you want the "30%" to be as exact as round-off will permit:
r = height(C);
ridx = randperm(r);
n1 = floor(r * .3);
n2 = r - n1;
C1 = C(sort(ridx(1:n2)),:);
C2 = C(sort(ridx(n2+1:end),:));
In the case that 30% should be statistical:
r = height(C);
mask = rand(r,1) <= 0.3;
C1 = C(mask,:);
C2 = C(~mask,:);
2 件のコメント
Walter Roberson
2021 年 9 月 1 日
In the first one,
C2 = C(sort(ridx(n2+1:end)),:);
) was in the wrong place.
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Logical についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!