How to remove all the rows if first two columns has same number?

1 view (last 30 days)
I have matrix like this. I wants to remove the all the rows which contain same numbers in first two columns
1 1 1 200 2
1 2 2 200 2
1 3 3 200 2
1 4 4 200 2
2 1 1 200 2
2 2 2 200 2
2 3 3 200 2
2 4 4 200 2
3 1 1 200 2
3 2 2 200 2
3 3 3 200 2
3 4 4 200 2
4 1 1 200 2
4 2 2 200 2
4 3 3 200 2
4 4 4 200 2
for example
1 2 2 200 2
1 3 3 200 2
1 4 4 200 2
2 1 1 200 2
2 3 3 200 2
2 4 4 200 2
3 1 1 200 2
3 2 2 200 2
3 4 4 200 2
4 1 1 200 2
4 2 2 200 2
4 3 3 200 2

Accepted Answer

Guillaume
Guillaume on 12 Jul 2019
Two of many possible ways:
yourmatrix(diff(yourmatrix(:, [1 2]), [], 2) == 0 , :) = [];
yourmatrix(yourmatrix(:, 1) == yourmatrix(:, 2), :) = [];

More Answers (0)

Categories

Find more on Portfolio Optimization and Asset Allocation in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!