How to filter multiple columns with conditions

조회 수: 13 (최근 30일)
Jana Sarran
Jana Sarran 2023년 4월 3일
댓글: Peter Perkins 2023년 4월 5일
I am trying to filter column 4 and column 6 of the table below:
I am using the "find" function - DV1 = find((DV.Veh1Type == 630) & (DV.Veh1Type == 640) & (DV.Veh2Type == 640) & (DV.Veh2Type == 630) ) but my cell is a 0×1 empty double column vector.
Can someone assist me with advice on a function that can be used to filter those columns so that only the vehicle type with number 630 and 640 remains in both columns?

채택된 답변

Walter Roberson
Walter Roberson 2023년 4월 3일
row_is_selected = ismember(VD.Veh1Type, [630 640]) & ismember(VD.Veh2Type, [630 640]);
subset = DV(row_is_selected, :);
  댓글 수: 2
Jana Sarran
Jana Sarran 2023년 4월 3일
Thank you! This code worked.
Peter Perkins
Peter Perkins 2023년 4월 5일
In other words, some of those &'s needed to be |'s. Which is what ismember does.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Descriptive Statistics에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by