How to repeat value from start in buffer function Matlab

2 ビュー (過去 30 日間)
Stephen john
Stephen john 2022 年 8 月 17 日
編集済み: Walter Roberson 2022 年 8 月 17 日
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
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.
Stephen john
Stephen john 2022 年 8 月 17 日
@Jan yes repeat the first 344 values, The buffer function place 0's to complete 1000 samples.
The should be generic using buffer function, for examples if i have 250 samples the buffer function place 750 zeros to complete 1000 samples. I want to to repeat value in place of 0's to complete 1000 samples

サインインしてコメントする。

採用された回答

Walter Roberson
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)
ans = 31×1
20 21 22 23 24 25 26 27 28 29

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

製品


リリース

R2022a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by