Split a vector into 2 vectors randomly
16 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Savvas Kontos
am 11 Jan. 2016
Kommentiert: Savvas Kontos
am 11 Jan. 2016
i have a vector of 4 columns and 150 rows named "samples". I want to put randomly the 120 rows in a new vector, and the remaining rows in a second new vector. I am new to matlab. can anyone help me? thanks in advance.
0 Kommentare
Akzeptierte Antwort
Robert
am 11 Jan. 2016
I think you will find the function randperm useful. You can use it to generate a random order for your 150 rows and then select the first 30 for your smaller set and the last 120 for the larger set (order not important).
For example
my_indices = randperm(150);
small_set = data(my_indices(1:30),:);
large_set = data(my_indices(31:end),:);
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!