How to extract rows given multiple ranges
12 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
So i have a dataset and I'm trying to downsize it, I have data sorted and have extracted the row indeces required to downsize the dataset while maintaining an almost equal amount of samples per class.
Here are the the specified rows. The dataset has 500,000 samples, using these rows downsizes it to about 120,000. I just want to know what I can to extract these from the original dataset keeping all the columns.
[0:5000,34586:39586,72961:77961,107165:112165,142309:147309,175845:180845,207262:212262,241495:246495,277250:282250,311197:316197,345045:350045,351453:354453,355332:359332,359895:362895,363048:365048,365517:370517,373755:378755,398739:403739,408560:413560,421163:425163,425859:427859,428631:433631,438809:443809,447548:452548,462867:467867,474286:476286,477036:479036,480031:485031,498294:500294]
0 Kommentare
Akzeptierte Antwort
KSSV
am 30 Mai 2022
Bearbeitet: KSSV
am 30 Mai 2022
If you have the indices of rows idx, you can just use
iwant = A(idx,:) ; % where A is your matrix and idx are the row indices
to extract the rows from A wih all the columns.
Note: MATLAB indexing start from 1 and indices should be positive integers or logicals.
In your case, the first number: 0:5000 should be 1:5000.
% EXample
A = magic(10) % dummy data for demo
idx = [1 3 5 7] ; % extrcat these rows from A
iwant = A(idx,:)
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Database Toolbox finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!