Replacing values in vector segments with highest value
Mostra commenti meno recenti
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 Commenti
OCDER
il 9 Gen 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
il 9 Gen 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
il 10 Gen 2019
Risposta accettata
Più risposte (0)
Categorie
Scopri di più su Whos in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!