How can I split measured data in separate vectors, depending on sign value?
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Anna B.
el 7 de Mzo. de 2022
Comentada: Star Strider
el 7 de Mzo. de 2022
Hello! Is it possible to split measured data f.e.v= [1 2 3 4 5 4 3 2 1 2 3 4 5 4 3 2 1] in separate vectors, f.e. only the 'growing' values: v1=[1 2 3 4 5], v2=[1 2 3 4 5].
Maybe with a find(sign(diff(v))==1) ?
Thank you!
0 comentarios
Respuesta aceptada
Star Strider
el 7 de Mzo. de 2022
One approach —
v= [1 2 3 4 5 4 3 2 1 2 3 4 5 4 3 2 1];
dv = gradient(v);
sel = v(dv>=0);
dsel = diff([1 find(diff([sel(1) sel])<0) numel(sel)+1]);
C = mat2cell(sel, size(sel,1), dsel)
v1 = C{1}
v2 = C{2}
.
2 comentarios
Más respuestas (1)
Jan
el 7 de Mzo. de 2022
Editada: Jan
el 7 de Mzo. de 2022
Start with a simple loop approach:
v = [1 2 3 4 5 4 3 2 1 2 3 4 5 4 3 2 1];
dv = [false, diff(v) > 0, false];
ini = strfind(dv, [false, true]);
fin = strfind(dv, [true, false]);
C = cell(1, numel(ini));
for iC = 1:numel(ini)
C{iC} = v(ini(iC):fin(iC));
end
C
1 comentario
Ver también
Categorías
Más información sobre Multirate Signal Processing 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!