Effacer les filtres
Effacer les filtres

What wrong with the code?

2 vues (au cours des 30 derniers jours)
GEORGIOS BEKAS
GEORGIOS BEKAS le 8 Jan 2018
Commenté : Stephen23 le 8 Jan 2018
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 commentaire
Stephen23
Stephen23 le 8 Jan 2018
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);

Connectez-vous pour commenter.

Réponse acceptée

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

Plus de réponses (0)

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Tags

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by