Info

この質問は閉じられています。 編集または回答するには再度開いてください。

Compare Vectors of Different Sizes and print the results

1 回表示 (過去 30 日間)
Zekeftw
Zekeftw 2016 年 3 月 30 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
Hi,
I am trying to compare vector A to vectors B, C, and D. If an element from vector A does not appear in vectors B, C, and D I would like to print it out.
For Example:
A = [15.00; 20.00; 7.50; 8.75; 30.00; 125.00; 12.25]
B = [35.00; 25.00; 15.00; 15.00; 20.00; 7.50; 30.00; 125.00; 12.25]
C = [0.00; 5.00; 0.00; 0.00; 10.00; 0.00; 0.00; 0.00; 0.00]
D = [35.00; 30.00; 15.00; 15.00; 30.00; 7.50; 30.00; 125.00; 12.25]
I would like to print out that 8.75 was missing from vectors B, C, and D.
Thank you
  1 件のコメント
jgg
jgg 2016 年 3 月 30 日
This should do it:
out = A(ismember(A,[B;C;D]) == 0)
You can then output the out values however you want. Note, I assume you meant if it doesn't appear in any of the three vectors (as written). You'd have to change the condition slightly if you meant all of them at the same time.

回答 (1 件)

Azzi Abdelmalek
Azzi Abdelmalek 2016 年 3 月 30 日
setdiff(A,[B,C,D])

この質問は閉じられています。

Community Treasure Hunt

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

Start Hunting!

Translated by