Collapsing data that are within one integer value of each other
1 次查看(过去 30 天)
显示 更早的评论
So I've run in to a problem utilizing the zeros generated from using fnzeros. I am able to condense down these zero points, but I need them condensed even more. Basically, there are multiple points in this 1x40 array that are within 1 integer value of each other (19, 20, 21...etc.). They are sometimes groups of 3, but also groups of 2 values which are within 1 integer value of each other. Because of this, if I try to index in steps such as 1:2:length(z) then it will get rid of points that I need. My goal is if there are three values i.e. 19,20,21 then the average is kept (20) and if there are two values then one number is kept i.e. 673,674 will keep 674. I have thought about utilizing logical indexes or possibly sorting the data and then trying to remove the values, but am having trouble figuring out the proper way to do this. I know that since it is a small 1x40 array that I can manually pluck out the data points, but this is very inefficient.
z =
19 20 21 136 382 631 673 674 760 761 762 877 1124 1372 1414 1415 1501 1502 1503 1618 1865 2113 2155 2156 2242 2243 2244 2360 2606 2854 2896 2897 2983 2984 2985 3100 3347 3595 3637 3638
inx = 1:length(SA);
sp = spline(inx,SA);
z = fnzeros(sp);
z = round(z(1,:));
0 个评论
采纳的回答
Andrei Bobrov
2018-7-3
编辑:Andrei Bobrov
2018-7-3
n = diff(z(:)) == 1;
lo = [n;0] | [0;n];
nn = [diff([0;n]) == 1;0];
nn(~lo) = 1;
out = ceil(accumarray(cumsum(nn),z(:),[],@mean));
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Spline Postprocessing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!