How to extract rows given multiple ranges
조회 수: 11 (최근 30일)
이전 댓글 표시
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
채택된 답변
KSSV
2022년 5월 30일
편집: KSSV
2022년 5월 30일
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
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Matrices and Arrays에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!