How to input signal to skip numbers and generate data?
1 次查看(过去 30 天)
显示 更早的评论
I have a set of random 0s and 1s matrix A = [0 0 0 0 0 1 1 1 0 0 0 0 1 0 1 1 0 0 1 1 1 1 1 0 0 0 0]. I want to create a matrix B that has the same size as A that if i input an interval of say 'n', it skips n numbers, and if it lands on 1, it records 1 but if it lands on 0 it records 0. however, if it doesnt land on 1 for a long time and finally lands on a 1, it records a 1 even though it has skipped more than n numbers. How do I create this matrix B?
For example, n = 2, then matrix B = [0 0 0 0 0 1 0 0 0 0 0 0 1 0 0 1 0 0 1 0 0 1 0 0 0 0 0]
0 个评论
采纳的回答
Mara
2021-1-27
A = [0 0 0 0 0 1 1 1 0 0 0 0 1 0 1 1 0 0 1 1 1 1 1 0 0 0 0];
n = 2;
B = zeros (1,length(A));
count = 0;
for i = 1:length(A)
count = count + 1;
if A(i) == 1 && count > n
B(i) = 1;
count = 0;
end
end
Does this help you?
5 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!