フィルターのクリア

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 Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by