How to pick out single occurring elements of an array

1 回表示 (過去 30 日間)
Femi Bolarinwa
Femi Bolarinwa 2020 年 11 月 19 日
コメント済み: Femi Bolarinwa 2020 年 11 月 20 日
I'm trying to use a for/while loop to pick out elements of an array that only occur once
For example: i want to pick out elements that occur just once in this array A = [2 4 6 7 3 9 0 3 5 7 3 5 2 4]
i want to put those single occurence elements in another say B = [6 0 9]
Im trying to avoid using 'unique' syntax because it doesnt work in real time simulink environment. So im trying to build it from basics while/for loop
Thanks in advance
  3 件のコメント
Femi Bolarinwa
Femi Bolarinwa 2020 年 11 月 19 日
Im trying to avoid using unique because it doesnt work in real time simulink environment. So im trying to build it from basics while/for loop
Rik
Rik 2020 年 11 月 20 日
How is it not working? Is there a doc page that describes these limitations? I never heard of such limitations.

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

採用された回答

Setsuna Yuuki.
Setsuna Yuuki. 2020 年 11 月 19 日
編集済み: Setsuna Yuuki. 2020 年 11 月 19 日
you can try with a conditional and counter:
count = 0;
l = 1;
for n=1:length(A)
for m = 1:length(A)
if(A(n) == A(m))
count = count+1;
end
end
if(count == 1)
b(l) = A(n);
l = l+1;
end
count = 0;
end

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by