Info
この質問は閉じられています。 編集または回答するには再度開いてください。
Finding series of values within array
1 回表示 (過去 30 日間)
古いコメントを表示
Hi, I am up for a problem which I cannot totally solve.
Imagine I have an array: testtimes=[0.2 1.2 1.202 1.205 1.209 1.8 2.1 2.6 2.604 2.606 3.601 3.603 3.605]; Now I need to find all series of values where the difference between values is less than 0.01. So for now I did this:
if true
% code
end
% reference = 0.01
% isitesttimes=diff(testtimes); belowBIthreshold=(isitesttimes<reference);
% belowBIthreshold = [false, belowBIthreshold, false];
% edges = diff(belowBIthreshold);
% rising = find(edges==1); falling = find(edges==-1); spanWidth = falling - rising; wideEnough = spanWidth >= 3;
% startPos = rising(wideEnough);
% endPos = falling(wideEnough)-1;
% allInSpan = cell2mat(arrayfun(@(x,y) x:1:y, startPos, endPos, 'uni', false))
However, the answer now is
allInSpan = 2 3 4
Which means that on position 2,3,4 in testtimes the values are postioned which have a difference less than 0.01. However, the correct answer in this example would be 2,3,4,5 (since also position 5 has a difference of less than 0.01 compared to the one on position 4) (apart from that 8,9,10,11,12,13 should also be in the answer but that has to do (I guess) with the cut-off/Span-Width of 3).
Can somebody help me out?
Regards
0 件のコメント
回答 (0 件)
この質問は閉じられています。
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!