は論理インデックスとdiff
機能の組み合わせを使用して、このような何かを試してみてください。詳細
についてのコメントを参照してください
% Test data (column vector of values greater or less than 10)
mydata = [10, 9, 9, 10, 9, 10, 9, 9, 9, 10, 10, 10, 9, 9, 10]';
% Test for values less than 10
lowvalues = mydata(:,1) < 10;
% Get differences of test, for consecutive logic
consec = [0; diff(lowvalues)];
% Apply logic for more than 1 consecutive "lowvalues" element being true consecutively
output = [(consec(1:end-1) == 1 & consec(2:end) == 0) | ...
(consec(1:end-1) == 0 & consec(2:end) == 0 & lowvalues(1:end-1) == 1) | ...
(consec(1:end-1) == 0 & consec(2:end) == -1); false]
% First test: elements at start of consectutive list
% Second test: elements in the middle of consecutive list, which are low values
% Third test: elements at the end of the consecutive list
結果:あなたが見ることができるように、単独の9が連続したグループ内のように見える、とすべてのグループ化された9Sがあるされていない
% Test data and output:
mydata = [10, 9, 9, 10, 9, 10, 9, 9, 9, 10, 10, 10, 9, 9, 10]'
output = [ 0, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 0]'
。あなたはfind(output)
を使ってインデックスを得ることができます。
あなたは
desireddata = mydata(output);
% result: [9,9,9,9,9,9,9], the elements 2,3,7,8,9,13,14 from mydata
編集使用して所望のデータのみを抽出することができます。
だけdesireddata
文を変更して、これを満たす行列から行を取得することを。つまり、上記のmydata
を連続した値をテストする列に置き換えます。
% Take the consecutive-value rows and all of the columns from a matrix
myConsecutiveValuesMatrix = myWholeMatrix(output, :)
どのくらい連続していなければなりませんか?最初の連続したセット、または連続したデータを含むすべてのグループが必要ですか?どのコードを試しましたか? – Wolfie
10より小さいインデックスを見つけて連続したインデックスを作成し、最終的に結果を得るためにデータをインデックス化します – GameOfThrows
また、Image Processing Toolboxはありますか?イメージ処理ツールボックスのいくつかの機能を使用して、すばやく、頑強な方法でそれを行うことができます。 – edwinksl