Replacing values in vector segments with highest value
Show older comments
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 Comments
OCDER
on 9 Jan 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
on 9 Jan 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
on 10 Jan 2019
Accepted Answer
More Answers (0)
Categories
Find more on Whos in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!