Replacing values in vector segments with highest value
显示 更早的评论
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 个评论
OCDER
2019-1-9
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
2019-1-9
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
2019-1-10
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Whos 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!