フィルターのクリア

find a row number in text file for certain condition

2 ビュー (過去 30 日間)
sermet OGUTCU
sermet OGUTCU 2021 年 4 月 26 日
コメント済み: Jan 2021 年 4 月 26 日
data=[1.2;1.0;0.05;0.4;0.3;0.2;0.1;0.05;0.04;0.03;0.03;0.02;0.01;0.001;0.01;0.01;0.001 ] ;
Here, the answer to my problem is 8th row, because the 10 consecutive rows from the 8th row are smaller than 0.10. How can I write a code to determine the row number which satisfies this condition?
  2 件のコメント
Jan
Jan 2021 年 4 月 26 日
編集済み: Jan 2021 年 4 月 26 日
Why do you menation a text file?
sermet OGUTCU
sermet OGUTCU 2021 年 4 月 26 日
The text file includes the numeric data as n (row) x 1 (column)

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

採用された回答

Jan
Jan 2021 年 4 月 26 日
data = [1.2;1.0;0.05;0.4;0.3;0.2;0.1;0.05;0.04;0.03;0.03;0.02;0.01;0.001;0.01;0.01;0.001 ] ;
[b, n, index] = RunLength(data < 0.1);
match = find(b & n >= 10, 1);
result = index(match)
result = 8
function [b, n, index] = RunLength(x)
d = [true; diff(x(:)) ~= 0]; % TRUE if values change
b = x(d); % Elements without repetitions
k = find([d.', true]); % Indices of changes
n = diff(k); % Number of repetitions
index = k(1:numel(k) - 1);
if iscolumn(x)
n = n.';
index = index.';
end
end
  1 件のコメント
Jan
Jan 2021 年 4 月 26 日
[MOVED from flags] sermet OGUTCU wrote: This solution is highly effective.
@sermet OGUTCU: We use flags here to inform the editors about inappropriate contents like rudeness.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeText Data Preparation についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by