Random pick data by label
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hg
am 7 Aug. 2015
Bearbeitet: Azzi Abdelmalek
am 7 Aug. 2015
I have a data array (13x5). The last column is the class (1-4) of each data. How do I randomly pick n-number of data from each class? Let say 2 data from each class.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/147835/image.png)
0 Kommentare
Akzeptierte Antwort
Azzi Abdelmalek
am 7 Aug. 2015
Bearbeitet: Azzi Abdelmalek
am 7 Aug. 2015
A=[randi(9,100,4) randi([1 4],100,1)] % Example
[ii,jj,kk]=unique(A(:,5))
m=accumarray(kk,(1:numel(kk))',[],@(x) {x'})
out=cell2mat(cellfun(@(x) A(x(randperm(numel(x),2)),:),m,'un',0))
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Resizing and Reshaping Matrices 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!