How can I implement a rolling list ?
1 回表示 (過去 30 日間)
古いコメントを表示
I am reading data over the network in real time and I want to limit a dataset to 1000 points. For example when the array has filled 1000 points I want it to start at 1 again to save memory. I also want to ensure I keep the order so that when i plot the information it will plot oldest to newest and not in the way it was stored.
Is there any such feature in MATLAB?
0 件のコメント
採用された回答
Walter Roberson
2012 年 9 月 30 日
You could also consider
if length(data) == 1000
data(1) = [];
end
data(end+1) = theNewDataValue;
0 件のコメント
その他の回答 (3 件)
Image Analyst
2012 年 9 月 30 日
Something like this perhaps:
% Assign new data to the next element.
data(nextIndexToUse) = theNewDataValue;
% Increment to the next element to use.
nextIndexToUse = nextIndexToUse + 1;
% Reset back to 1 if it exceeds 1000
if nextIndexToUse > 1000
nextIndexToUse = 1;
end
0 件のコメント
Malcolm Lidierth
2012 年 9 月 30 日
編集済み: Malcolm Lidierth
2012 年 9 月 30 日
or
Edited for unity-based indexing as per @Blake's remark below:
x=zeros(1,1000)
circindex=@(k)mod(k-1,numel(x))+1
x(circindex(100001))=1
0 件のコメント
Blake
2012 年 9 月 30 日
編集済み: Blake
2012 年 9 月 30 日
1 件のコメント
Malcolm Lidierth
2012 年 9 月 30 日
@Blake
I forgot the unity-base in MATLAB. Code corrected above. To extract data with N samples:
x([circindex(N):-1:1 end:-1:circindex(N)+1])
Extra code for N<=0 not included.
参考
カテゴリ
Help Center および File Exchange で Logical についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!