フィルターのクリア

How to delete rows from a matrix when the values of certain columns are equal?

2 ビュー (過去 30 日間)
Vasiliki Charisi
Vasiliki Charisi 2015 年 10 月 15 日
回答済み: per isakson 2015 年 10 月 15 日
I have a matrix
M = [1 1 7 8; 2 3 6 9; 5 8 10 8; 4 4 3 1]
and I want to delete the rows that have the same value in the first and second column. In this example I want to delete the rows
1 1 7 8
4 4 3 1
and then have the remaining columns in the matrix:
M = [2 3 6 9; 5 8 10 8]
How do I do that?

採用された回答

per isakson
per isakson 2015 年 10 月 15 日
Try
>> M = [1 1 7 8; 2 3 6 9; 5 8 10 8; 4 4 3 1]
M =
1 1 7 8
2 3 6 9
5 8 10 8
4 4 3 1
>> M( M(:,1)==M(:,2),:)=[];
>> M
M =
2 3 6 9
5 8 10 8
and look up logical indexing in the Help.

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMultidimensional Arrays についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by