What wrong with the code?
조회 수: 2 (최근 30일)
이전 댓글 표시
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
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
2018년 1월 8일
I would subscript ‘x’ as ‘x(i)’ here, rather than using ‘x(1)’:
z = sum(find(y == x(i)))
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Logical에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!