Conditional Indexing of a cumsum

2 ビュー (過去 30 日間)
Jonathan Cheong
Jonathan Cheong 2021 年 2 月 4 日
コメント済み: Jonathan Cheong 2021 年 2 月 9 日
From a random data k, I would like to fulfill 2 Conditions:
1) Cumsum until 3.5mm - Fulfilled
2) Each cumsum interval must be more than 4 index
Below is the code:
clean = k([],:);
indclean = [];
k = rand(1000,1);
for ii = startind % Iterate over start indices
cs = cumsum(k(ii:end));
inds3_5 = ii-1 + find(cs <= 1); % Find where data is below the 3.5mm threshold; adjust based on the start index.
clean = [clean;k(inds3_5,:)]; % append data
indclean = [indclean; inds3_5]; % append indices
end
Hence, how do I make it so that only cumsum that last more than 4 indexes are used.
Many thanks.

採用された回答

Asvin Kumar
Asvin Kumar 2021 年 2 月 8 日
Store find(cs<=1) in a temporary variable and count the number of elements in that list.
tmp = find(cs<=1);
if numel(tmp)>=4
% your code here
end
  1 件のコメント
Jonathan Cheong
Jonathan Cheong 2021 年 2 月 9 日
Thank you very much! This is exactly what I was looking for.

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

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by