What wrong with the code?
1 次查看(过去 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 中查找有关 Matrix Indexing 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!