フィルターのクリア

Locate an element in an array

1 回表示 (過去 30 日間)
Mario Martos
Mario Martos 2016 年 5 月 22 日
コメント済み: Guillaume 2016 年 5 月 22 日
Hello, I wanted to ask about how to locate the items that I have in a matrix or vector in a larger matrix and remove the row in which it is located. For example I have the following matrix (in my case is bigger than this) :
a =
3.4000 5.5000 8.6000
2.4000 6.3000 7.7000
7.7000 2.3000 6.9000
8.8000 5.7000 9.9000
And another where the elements that interest me in to find are :
b =
6.3000 1.0000
5.7000 2.0000
And what I want and I want is to find the elements of the first column of b in the second column of a; and once found remove the entire row where these elements are b , resulting in :
res =
2.4000 6.3000 7.7000
8.8000 5.7000 9.9000
6.3000 and 5.7000 which are the elements of b found in a with its corresponding row. Thanks in advanced.

採用された回答

Andrei Bobrov
Andrei Bobrov 2016 年 5 月 22 日
編集済み: Andrei Bobrov 2016 年 5 月 22 日
res = a(ismember(a(:,2),b(:,1)),:);
  4 件のコメント
Andrei Bobrov
Andrei Bobrov 2016 年 5 月 22 日
Yes, corrected.
Mario Martos
Mario Martos 2016 年 5 月 22 日
Thank you very much , why not just catch me some elements of the array instead of all ... because there are more of the same but only identifies me and take a few

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

その他の回答 (1 件)

Guillaume
Guillaume 2016 年 5 月 22 日
From your example. it looks like you want to keep the rows where the elements are found, not remove. Anyway, to find which set of numbers belong to another set you use ismember:
%find which rows of the 2nd column of a belong to the first column of b, and keep these:
res = a(ismember(a(:, 2), b(:, 1)), :)
%and if you want to remove the rows, you simply invert the result of ismember:
%res = a(~ismember(a(:, 2), b(:, 1)), :)
  2 件のコメント
Mario Martos
Mario Martos 2016 年 5 月 22 日
Thank you very much , why not just catch me some elements of the array instead of all ... because there are more of the same but only identifies me and take a few
Guillaume
Guillaume 2016 年 5 月 22 日
I don't understand your sentence at all. If the answer is not what you want (it is according to what you've asked so far), then provide an example where the solution does not work and the result you would expect instead.

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

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by