Is there a way to get MATLAB to filter out specific rows in arrays?
조회 수: 20 (최근 30일)
이전 댓글 표시
I’ve been looking for a method to filter out specific rows of data in an array. I’ve got a < 750 x 3 double> array containg car data that looks like this:
10000.5 3 120
10001.0 5 112
10001.5 1 117
10002.0 4 119
10002.5 3 122
10003.0 2 120
10003.5 5 114
10004.0 1 118
10004.5 4 120
Where column 1 is track time, column 2 is the car number, and column 3 is the speed of the car at that specific track time. I’m looking for a method to filter out rows of data based on the car number. For example, if the data in the rows associated with car numbers 3 and 4 are not needed, I’d have a resulting array that looks like this:
10001.0 5 112
10001.5 1 117
10003.0 2 120
10003.5 5 114
10004.0 1 118
Eventhough I haven’t found a specific MATLAB funtion that will do this type of filtering, I would think this can be done in MATLAB. Any ideas are appreciated. Thanks.
댓글 수: 0
채택된 답변
Kelly Kearney
2013년 6월 26일
Take a look at the ismember function:
data = [...
10000.5 3 120
10001.0 5 112
10001.5 1 117
10002.0 4 119
10002.5 3 122
10003.0 2 120
10003.5 5 114
10004.0 1 118
10004.5 4 120]
new = data(~ismember(data(:,2),[3 4]),:)
추가 답변 (1개)
Lokesh Ravindranathan
2013년 6월 26일
The following code does filtering for your problem.
a = [10000.5 3 120;
10001.0 5 112;
10001.5 1 117;
10002.0 4 119;
10002.5 3 122;
10003.0 2 120;
10003.5 5 114;
10004.0 1 118;
10004.5 4 120];
list1 = a(:,1,:)
list2 = a(:,2,:)
list3 = a(:,3,:)
keyIndex = (list2~=3) &(list2~=4)
b = [list1(keyIndex) list2(keyIndex) list3(keyIndex)]
The matrix b returns the matrix of interest. There are other ways of implementing the filtering, but this is the simplest I could think of.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Logical에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!