thanks for your reply. Yes, I can explain it a bit more e.g. if we have a= [1 1 1 1 1 1 1 1 1 1 1 1] the output should be b= [1 1 1 1 1 0 1 1 1 1 1 0 1 1] The logic should insert an extra 0 after consecutive 5 ones start looking from the beginning of data.
Hi, Thanks for your reply. It is not working as desired because my data is not same all the time. Please see my reply to Paolo above. Starting from the first element the logic should insert extra 0 after 5 consecutive ones.
The code finds the first occurrence of[1 1 1 1 1] in the array and add a zero after that. In the next iteration, it skips the first part of the array and searches the remaining array. If another occurrence of 5 1s is found, it will again add zero and search the remaining array. It will continue until all the groups of 5 1s have passed.
You can set a breakpoint at first line of the code and execute the each line one by one to better understand the logic.
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
2 Comments
Direct link to this comment
https://fr.mathworks.com/matlabcentral/answers/407605-how-to-pad-extra-0-after-5-consecutive-1-s-in-an-array#comment_583033
Direct link to this comment
https://fr.mathworks.com/matlabcentral/answers/407605-how-to-pad-extra-0-after-5-consecutive-1-s-in-an-array#comment_583033
Direct link to this comment
https://fr.mathworks.com/matlabcentral/answers/407605-how-to-pad-extra-0-after-5-consecutive-1-s-in-an-array#comment_583034
Direct link to this comment
https://fr.mathworks.com/matlabcentral/answers/407605-how-to-pad-extra-0-after-5-consecutive-1-s-in-an-array#comment_583034
Sign in to comment.