필터 지우기
필터 지우기

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 CenterFile Exchange에서 Logical에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by