フィルターのクリア

What wrong with the code?

2 ビュー (過去 30 日間)
GEORGIOS BEKAS
GEORGIOS BEKAS 2018 年 1 月 8 日
コメント済み: Stephen23 2018 年 1 月 8 日
I want to create a data structure to find unique unsorted values, from an initial vector. I am doing something wrong.
y = []
j =1
for i = 1:length(x)
z = sum(find(y == x(1)))
if z <1
y(j) = x(i)
j = j+1
end
end
  1 件のコメント
Stephen23
Stephen23 2018 年 1 月 8 日
Why not just use unique?
U = unique(x,'first','stable')
or for older versions:
[U,X] = unique(x,'first');
[~,X] = sort(X);
U = U(X);

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

採用された回答

Star Strider
Star Strider 2018 年 1 月 8 日
I would subscript ‘x’ as ‘x(i)’ here, rather than using ‘x(1)’:
z = sum(find(y == x(i)))

その他の回答 (0 件)

カテゴリ

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