How to repeat value from start in buffer function Matlab
2 次查看(过去 30 天)
显示 更早的评论
Hello Everyone, I hope you are doing well. I have the data shape 1x66656
I apply buffer function to get every 1000 samples,
Now the shape of the matrix is 1000x67. The remaining 344 value from 656 value are replaced by 0, Instead of 0 i want to repeat the matrix from the start to complete 1000 samples.
buffered = buffer(incomingdata, 1000);
2 个评论
Jan
2022-8-17
What exactly does "repeat the matrix from the start" mean? The first value? The first 344 elements?
Providing a small example would clarify this.
采纳的回答
Walter Roberson
2022-8-17
编辑:Walter Roberson
2022-8-17
buffer() does not have any option for that.
The following code would be quite a bit shorter if we knew for sure that the incomingdata signal was already at least as large as the group size (1000)
%demo data
incomingdata = repmat((1:39).', 51, 1);
%the work
groupsize = 1000;
sig = incomingdata(:);
if isempty(sig)
error('signal is empty, cannot buffer it');
end
sigsize = numel(sig);
fullcopies = floor(groupsize ./ sigsize);
sig = repmat(sig, 1+fullcopies, 1);
sigsize = numel(sig);
leftover = mod(sigsize, groupsize);
if leftover ~= 0
sig = [sig; sig(1:groupsize-leftover)];
end
buffered = buffer(sig, groupsize);
%cross-check
buffered(end-30:end, end)
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!