필터 지우기
필터 지우기

Splitting a matrix by even and odd numbers

조회 수: 10 (최근 30일)
Chris Williams
Chris Williams 2013년 11월 12일
답변: Chris Williams 2013년 11월 12일
I have a 200x2 matrix. Column A contains a mixture of even and odd numbers. Column B contains 1s and 0s.
Where the numbers in Column A are even, I need to extract those rows into a new nx2 matrix. The numbers in Column A and B must remain correctly alligned.
Hope you can help!

채택된 답변

Jos (10584)
Jos (10584) 2013년 11월 12일
use rem to determine which list of numbers is even or odd
X = [1 3 4 2 5 4 2] % hint X is the first column of your matrix
iseven = rem(X,2)==0
use this logical vector to select the whole row of M

추가 답변 (1개)

Chris Williams
Chris Williams 2013년 11월 12일
Perfect, thanks!

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by