フィルターのクリア

Count conservative occurrences of zeros and if zero appeared for defined number of times it should be changed.

1 回表示 (過去 30 日間)
Hello,
There is an array A size (NxM), each column represents when a signal was created. I need to close that signal if certain time it was not created again and assign -1 value. For example like this:
1 0 1 0 1
0 1 0 1 0
0 0 1 0 0
1 0 0 1 1
0 0 1 1 0
0 1 0 0 0
I need to count consecutive occurrences of zero column-vise, and if zero occurred for defined number of times for example two, it should be changed to -1 and output should look like this:
1 0 1 0 1
0 1 0 1 0
-1 0 1 0 -1
1 -1 0 1 1
0 0 1 1 0
-1 1 0 0 -1
Count conservative occurrences of zeros and if zero appeared for defined number of times it should be changed.
  1 件のコメント
Jan
Jan 2018 年 7 月 8 日
編集済み: Jan 2018 年 7 月 8 日
I assume you mean "consecutive" instead of "conservative". What is the wanted output for:
x1 = [0; 0; 1]
x2 = [1; 0; 0; 0; 0]

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

採用された回答

Jan
Jan 2018 年 7 月 8 日
編集済み: Jan 2018 年 7 月 8 日
If you want to replace the 2nd element after a 1 by -1, if it was a 0 before:
A = double(rand(10, 5) < 0.3); % Some test data
n = 2;
pattern = [1, zeros(1, n)];
for k = 1:size(A, 2)
index = strfind(A(:, k).', pattern);
A(index + n, k) = -1;
end
  7 件のコメント
Jan
Jan 2018 年 7 月 9 日
@Mantas Vaitonis: strfind is not implemented for GPUs. If you have a C compiler installed, I'd suggest to try the MEX function. Which OS do you use? Can you work with UINT8 instead of DOUBLEs?
Mantas Vaitonis
Mantas Vaitonis 2018 年 7 月 9 日
@Jan, I am using WIN 10 64BIT, yes it would be possible to use UNIT8 instead of double, becasue this varibale valeus are 1, 0 or -1.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by