How to eliminate array which contain zero, negative values, repeated values, etc constraint?

Hi, I have n=6 and for example I have several set of points ( with 6 elements),
a=[1 5 1 6 2 6];
b=[2 5 1 6 2 5];
c=[3 5 1 6 2 4];
d=[0 4 1 6 3 7];
e=[1 4 1 6 3 6];
f=[-1 3 1 6 4 8];
I wish to eliminate the set which contain zero, negative values,elements greater than n=6 and repeated values. At the end, left set c. The others are eliminated due to:
a-repeated value 1 and 6
b-repeated value 2 and 5
d-contain zero, and 7 (which is greater than 6)
e-repeated value 1 and 6
f-contain negative value and 8 (greater than 6).
Thanks in advance.

 採用された回答

Andrei Bobrov
Andrei Bobrov 2014 年 11 月 11 日
編集済み: Andrei Bobrov 2014 年 11 月 11 日
a=[1 5 1 6 2 6];
b=[2 5 1 6 2 5];
c=[3 5 1 6 2 4];
d=[0 4 1 6 3 7];
e=[1 4 1 6 3 6];
f=[-1 3 1 6 4 8];
M = [a;b;c;d;e;f];
out = M(all(M > 0,2) & cellfun(@(x)numel(unique(x)) == numel(x),num2cell(M,2)),:);

4 件のコメント

Grace
Grace 2014 年 11 月 11 日
編集済み: Grace 2014 年 11 月 11 日
Hi Andrei,
What about the constraint of eliminate the set which contain at least one element that is greater than n=6?
Thank you.
Michael Haderlein
Michael Haderlein 2014 年 11 月 11 日
I guess that's left for you as exercise ;-) Hint: It's similar to the condition of all positive values.
Grace
Grace 2014 年 11 月 11 日
編集済み: Grace 2014 年 11 月 11 日
Yup, get it. add in
all(M<=6,2)
Thanks :)
in your case
out = M(all(diff(sort(M,2),1,2) == 1,2) & all(M <= 6,2),:);

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeElementary Math についてさらに検索

タグ

質問済み:

2014 年 11 月 11 日

コメント済み:

2014 年 11 月 11 日

Community Treasure Hunt

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

Start Hunting!

Translated by