フィルターのクリア

How to find a minimum amount of equal adjacent values in an array?

2 ビュー (過去 30 日間)
Lennard Pol
Lennard Pol 2020 年 11 月 12 日
コメント済み: Lennard Pol 2020 年 11 月 18 日
Hi all,
I have a column vector X of 3000 data points long (15 min averaged data). To check whether a certain system freezed for at least a certain period of time, I want to check this array for a minimum of 100 adjacent data points with the exact same value.
I started like this:
diff_X = diff(X);
movingsum_X = movsum(diff_X,100);
flatlines = find(movingsum_X == 0);
Despite this giving results that are partly satisfying, it doesn't do the trick all the way unfortunately.
Anyone that can help me out extending this to a fully working script? Other ways to reach the goal are welcome too, thanks.
Lennard
  3 件のコメント
Bruno Luong
Bruno Luong 2020 年 11 月 16 日
編集済み: Bruno Luong 2020 年 11 月 16 日
Your code is flawed and fails if the signal is sum of pure oscillations (signal without DC component). Change
diff_X = diff(X)
to
diff_X = abs(diff(X))
will fix the flaw.
Lennard Pol
Lennard Pol 2020 年 11 月 18 日
This improved the performance, thanks!

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

採用された回答

Setsuna Yuuki.
Setsuna Yuuki. 2020 年 11 月 16 日
You can test this code with different A matrix:
x = 2;
% X x 3000 matrix of example
% A = ones(x,1000); %there is always error
% A = [3*ones(2,25) 4*ones(2,48) 2*ones(2,2901)]; % there is error after 147 cycles
% A = rand(x,3000); % there is never error
B = reshape(A,1,x*length(A));
cont = 0; contM = 0;
for n = 1:length(B)-99 % n indicates the number that is repeated 100 times
for m = n:(n+99)
if(B(n) == B(m)) %Compare wit future values
cont = cont+1;
end
end
if (cont == 100) %If cont == 100 the system has stopped
fprintf("Error in system \n");
break; %Only if you want stop analysis
else
fprintf("Good luck \n"); %Good luck
end
cont = 0;
end
  1 件のコメント
Lennard Pol
Lennard Pol 2020 年 11 月 18 日
Valuable contribution, thanks Bastian!

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

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by