Replacing values in vector segments with highest value
Mostrar comentarios más antiguos
Hi,
I have a vector [1x100] with positive numbers or zeroes. In example: [0 0 0 2 0 3 0 0 0 0 4 0 4 0 0 0 0 0 0 0 5.....].
The wanted result is same length vector which checks condition: if numbers > 0 occur in 3 consequent places, replace that segment with highest number in that segment. This means that my example vector should look like this: [0 0 0 3 3 3 0 0 0 0 4 4 4 0 0 0 0 0 0 0 5....]
3 comentarios
OCDER
el 9 de En. de 2019
And what if you have:
A = [ 1 0 2 0 3 0 4 0 5 0 6 ]?
Is the expected answer:
B = [ 6 6 6 6 6 6 6 6 6 6 6 ]?
or
B = [ 2 2 3 3 4 4 5 5 6 6 6 ]?
Adam Danz
el 9 de En. de 2019
But nowhere in your example are there 3 consecutive numbers greater than zero.
Judging from your example, you're searching for any number greater than zero within 3 indices from another number greater than zero.
What would be the output for this number?
[0 0 0 2 0 3 0 5 0 6 4 0 4 0 0 0 0 0 0 0 5]
Matas Dijokas
el 10 de En. de 2019
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Whos 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!