Remove the rows/columns with single values of a matrix
조회 수: 1 (최근 30일)
이전 댓글 표시
Hello,
I have a matrix quite big (A < 23 x 250000 >). I want to evaluate the first row A(1,:) and eliminate the columns where there are values only repeated once. The number in this first row is an integer and always is increasing.
Lets say:
B = [1 1 3 5 5 5 7 9 9
0.1 0.5 0.2 0.4 0.3 0.9 0.1 0.6 0.5]
The result should be:
B = [1 1 5 5 5 9 9
0.1 0.5 0.4 0.3 0.9 0.6 0.5]
I know how to do it with for and if statements but I think it won't be efficient because the size of the matrix.
Many thanks!
댓글 수: 0
채택된 답변
Dani Tormo
2012년 11월 28일
추가 답변 (1개)
per isakson
2012년 11월 28일
편집: per isakson
2012년 11월 28일
A start:
B = [1 1 3 5 5 5 7 9 9
0.1 0.5 0.2 0.4 0.3 0.9 0.1 0.6 0.5];
[ uniqueB, ix ] = unique( B(1,:) );
sB = B(1,:);
sB( ix ) = [];
singleB = setdiff( uniqueB, sB );
[ ~, ixm ] = ismember( singleB, B(1,:) );
B( :, ixm ) = []
prints
B =
1.0000 1.0000 5.0000 5.0000 5.0000 9.0000 9.0000
0.1000 0.5000 0.4000 0.3000 0.9000 0.6000 0.5000
>>
your turn.
I'm wouldn't be surprise if the for-loop is faster :)
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Debugging and Analysis에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!