extract multiple submatrices from a large matrix based on specific criterion

I have a Matrix A (162301x13 double) which first column contains 625 different ID numbers (they repeat that is why i have 162301 rows) and the other columns contain SL values for 12 different frequency values.
i need to extract submatrices from this large matrix for each unique ID value. For example (see attached), ID 23 contains 8 rows of values for the SLs columns and i want to extract this submatrix from the large matrix.
Any ideas?
Thanks

 채택된 답변

madhan ravi
madhan ravi 2019년 5월 14일
편집: madhan ravi 2019년 5월 14일
T=readtable('mydatfile.csv')% Note here it’s just your filename;
Wanted = T(T.id==23,:) %

댓글 수: 9

Sorry, your answer helped me! thanks a lot
Since it would be too time consuming if i change the ID number manually, do you know an alternative way to do it? like a loop or something?
Those are the IDs that I have (attached)
u = unique(T.id);
for k = 1:u
Wanted{k} = T{T.id==23,:};
end
When i use this code, matlab stores only T.id==23 k times and that is not what i need. i need to have k number of submatrices for each ID number at the end
u = unique(T.id);
for k = 1:numel(u)
Wanted{k} = T{T.id==u(k),:};
end
Now it works!
Thank you a lot
Just one last question, how do I conver this multiple cell arrays (1x379) in multiple matrices?
cat(3,Wanted{:}) % works only if each cell has same number of rows otherwise keeping it this way is the only option.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기

태그

질문:

2019년 5월 14일

댓글:

2019년 5월 14일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by