How do I extract the rows of a matrix when I have the row numbers stored in another vector?
조회 수: 2 (최근 30일)
이전 댓글 표시
I have a 102x3 matrix, I need to extract all the rows that have the number 1 in the first column and put them in a separate matrix.
Ive tried using the find function to produce a vector listing all the row numbers of when this occurs however I am not sure how to use this to extract the whole rows from the large matrix.
댓글 수: 0
채택된 답변
Wayne King
2013년 4월 28일
편집: Wayne King
2013년 4월 28일
A = randi([0 4],102,3);
idx = find(A(:,1) == 1);
B = A(idx,:);
Another way:
B = A(A(:,1)==1,:);
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Shifting and Sorting Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!