フィルターのクリア

mutual array between two matrix

2 ビュー (過去 30 日間)
alexaa1989
alexaa1989 2014 年 8 月 11 日
回答済み: Andrei Bobrov 2014 年 8 月 11 日
Hi everyone I need to eradicate mutual arrays between matrix Y and matrix Z and put the rest of Z in another matrix to make more clear:
Y=[8,4,2,1,7,3,5,6];
Z=[5,2,1,6,8,3,4,7];
Now I need to choose for example '2' and '7' in Y and consequently eliminate '2' and '7' in Z and keep the rest of Z (5,1,6,8,3,4) in for example R
can someone tell me how to code that?
thank you all in advance.
  1 件のコメント
Hikaru
Hikaru 2014 年 8 月 11 日
This question is not that clear to me. What are the conditions to pick '2' and '7' in Y?

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

回答 (3 件)

Iain
Iain 2014 年 8 月 11 日
Two ways:
R = setdiff(Z,Y);
That'll remove every element of Y that appears in Z.
Aleternatively, use this approach
R = Z;
eliminate_this = Y(1);
R(R == eliminate_this) = [];
You'll need to add in the right loops, and index Y correctly.

Azzi Abdelmalek
Azzi Abdelmalek 2014 年 8 月 11 日
Z=[5,2,1,6,8,3,4,7];
a=[2 7]
Z(ismember(Z,a))=[]

Andrei Bobrov
Andrei Bobrov 2014 年 8 月 11 日
k = [2, 7];
t = ismember(k,Y);
if all(t)
R = Z(~ismember(Z,k));
end

カテゴリ

Help Center および File ExchangePerformance and Memory についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by