I need to partition an input vector v into smaller series of subvectors each containing the whole array of a periodic pattern given by a local sum of successive elements in the array.

3 次查看(过去 30 天)
I need to partition an input vector v into smaller series of subvectors each containing the whole array of a periodic pattern given by a local sum of successive elements in the array. I am recording some oscillations in a biological system. The vectors that I analyze represent an array of successive timings between followed events and under some stimulation they follow a certain periodicity . The pattern has two main characteristics: 1- the oscillations are periodic according to period reflected in a constant sum of successive elements of the array that repeats itself. The period varies from one vector to another and cannot be predicted ahead. Hence it is not the same for all vectors 2- many elements in the array are iterated because the system stabilizes at a constant oscillation pattern from which we can easily see the period. However the subvector of the whole pattern is more extended starting with the very early elements whose periodicity are respected by the sum of consecutive elements even if they do not follow exactly the iteration. For example this is a typical vector
v = [14 97 38 41 22 6 27 55 55 22 33 22 6 27 22 33 55 1 35 19 22 33 22 33 22 33 22 33 22 33 55 12 18 23 67 92 12]
in this case the periodicity of oscillation is 55. Note that
22+33 = 22+6+27 = 1+35+19 = 55
I need to extract the subvector with all elements for which the sum of consecutive elements is 55 which is a
a = [22 6 27 55 55 22 33 22 6 27 22 33 55 1 35 19 22 33 22 33 22 33 22 33 22 33 55]
and the starting and ending indices of the subvector from the original vector
i=[5 31]
I have no words to thank you for any suggestion on how to tackle this!

采纳的回答

Stephen23
Stephen23 2016-2-26
编辑:Stephen23 2016-2-26
v = [14,97,38,41,22,6,27,55,55,22,33,22,6,27,22,33,55,1,35,19,22,33,22,33,22,33,22,33,22,33,55,12,18,23,67,92,12];
N = 55;
idx = v==N;
tmp = v;
for k = 2:numel(v);
tmp = v + [0,tmp(1:end-1)];
idy = find(tmp==N);
idz = bsxfun(@minus,idy(:),k-1:-1:0).';
idx(idz) = true;
end
out = v(idx);
and check the output:
% test:
a = [22,6,27,55,55,22,33,22,6,27,22,33,55,1,35,19,22,33,22,33,22,33,22,33,22,33,55]
isequal(a,out)
and get the indices:
find(idx,1,'first')
find(idx,1,'last')
  14 个评论
Stephen23
Stephen23 2016-3-2
I have attached to this comment one function (named split) and one test script. I believe that the function does what you want, based on your examples.
The test script runs every example you have given me here, and compare the functions output with the expected output. They all pass :)

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Numeric Types 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by