matrix

12 ビュー (過去 30 日間)
khalil
khalil 2012 年 4 月 19 日
how I can remove rows from matrix each elements in these rows are equals m=[1 2 3;1 1 1;4 5 8;4 5 8;1 1 1;1 1 1;1 1 1;1 1 1;1 1 1;1 1 1;1 1 1;1 1 1;4 5 8;7 8 5; 47 9 5;7 8 5;5 322 5;7 8 55];

採用された回答

Andrei Bobrov
Andrei Bobrov 2012 年 4 月 19 日
m=[1 2 3;1 1 1;4 5 8;4 5 8;1 1 1;1 1 1;1 1 1;1 1 1;1 1 1;1 1 1;1 1 1;1 1 1;4 5 8;7 8 5; 47 9 5;7 8 5;5 322 5;7 8 55];
variant 1
[a b n] = unique(m,'rows','first');
[id id] = sort(b);
out1 = a(id,:);
variant 2
[a b n] = unique(m,'rows','first');
[id id] = sort(b);
t = accumarray(n,ones(numel(n),1)) == 1;
a2 = a(id,:);
out2 = a2(t(id),:);
  1 件のコメント
khalil
khalil 2012 年 4 月 19 日
Thank you.
The first variant is good solution for me

サインインしてコメントする。

その他の回答 (2 件)

Geoff
Geoff 2012 年 4 月 19 日
m(row, :) = [];
Where row is the row index, or vector of row indices.

Jan
Jan 2012 年 4 月 19 日
I do not understand the question. What does "each element in the rows are equals" mean? Do you want to remove rows, which have have equal elements only? Then:
m = [1 2 3;1 1 1;4 5 8;4 5 8;1 1 1;1 1 1;1 1 1;1 1 1; ...
1 1 1;1 1 1;1 1 1;1 1 1;4 5 8;7 8 5; 47 9 5; ...
7 8 5;5 322 5;7 8 55];
m = m(any(diff(m, 1, 2), 2), :);

カテゴリ

Help Center および File ExchangeDynamic System Models についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by