Splitting a table to 2
8 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hello all, I have a table named A. I want to split it into 2 sub-tables: Table 1 has 60% of the rows in A, chosen randomly. Table 2 has all the other rows that are not in table 1. Any elegant idea on how to do this?
0 commentaires
Réponse acceptée
KL
le 16 Août 2017
dummy = 10*rand(10,4);
T = array2table(dummy)
ranRows = randperm(length(dummy));
T1 = T(ranRows(1:(0.6*length(dummy))),:)
T2 = T(ranRows((0.6*length(dummy))+1:end),:)
2 commentaires
Guillaume
le 16 Août 2017
ranrows = randperm(height(T));
T1 = T(ranRows(1:0.6*height(T)), :);
T2 = T(ranRows(0.6*height(T)+1:end), :);
To avoid a warning, I would also wrap the 0.6*height(T) calculation inside a ceil, a floor or a round.
Plus de réponses (2)
Sean de Wolski
le 16 Août 2017
If you're looking to split your data into a training and testing set, then it might pay to look at cvpartition as well, it provides more options for splitting tables.
0 commentaires
Voir également
Catégories
En savoir plus sur Logical dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!