How to return a true/false logical array from a string array of repeating numbers?
Mostrar comentarios más antiguos
ans = 3 2 1 5 1 4 0
I want this to return a 7x1 logical array 0 0 1 0 1 0 0. Corresponding to the repeating “1” in the ans variable. Or 1 1 0 1 0 1 1. Whichever is easier to program. How do I do this?
Respuesta aceptada
Más respuestas (1)
Jon
el 7 de Jul. de 2022
x = [3 2 1 5 1 4 0]
L = x == 1
5 comentarios
Liv
el 7 de Jul. de 2022
Sorry I misunderstood what you were looking for. I think this does what you want:
x = [3 3 2 1 5 1 0 4]
u = unique(x)
[N,edges,bin]= histcounts(x,[u,u(end)+1])
N(bin)>1
Jon
el 7 de Jul. de 2022
Does this also do what you want?
Liv
el 7 de Jul. de 2022
That's fine as long as you have a solution, but I'm puzzled, as to why you would have array bounds errors, when as you can see it ran without issues in the small example I show above. As you had an array bounds error, are you sure you used :
[N,edges,bin]= histcounts(x,[u,u(end)+1])
and not:
[N,edges,bin]= histcounts(x,[u,u(end+1)])
Categorías
Más información sobre Operators and Elementary Operations en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!