Compute the complement of a set of indices in a known range

77 ビュー (過去 30 日間)
Brando Miranda
Brando Miranda 2016 年 4 月 4 日
編集済み: Brando Miranda 2016 年 4 月 6 日
I want to compute the complement of a set C. The elements are indices in the range 1 to K. Is the best/fastest/simplest way to go around this is using
C = setdiff(A,B)
or since I know they are not arbitrary sets of numbers, is there a better way to go around in MATLAB?
  2 件のコメント
Azzi Abdelmalek
Azzi Abdelmalek 2016 年 4 月 4 日
What do you mean? can you clarify what "not arbitrary sets of numbers" means, with a small example
Brando Miranda
Brando Miranda 2016 年 4 月 6 日
編集済み: Brando Miranda 2016 年 4 月 6 日
I just have susbets from a set of indices. So A Union B is the same as 1 to K. So the sets A and B are always in a predefined set of indices 1 to K. An example would be A=[1,2,5] and B=[3,4].
But I wouldn't get as input A=[0.1, 0.2], B = [0.5] since that is not a valid index range in question.

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

回答 (1 件)

Dave Behera
Dave Behera 2016 年 4 月 6 日
Your approach with setdiff seems to be the best way because it is the simplest. I recommend you to use it.

カテゴリ

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