Collapsing data that are within one integer value of each other
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Michael Jacobson
el 2 de Jul. de 2018
Comentada: Michael Jacobson
el 3 de Jul. de 2018
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 comentarios
Respuesta aceptada
Andrei Bobrov
el 3 de Jul. de 2018
Editada: Andrei Bobrov
el 3 de Jul. de 2018
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));
Más respuestas (0)
Ver también
Categorías
Más información sobre Spline Postprocessing en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!