Group values in a vector
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Panos Kerezoudis
el 26 de Jun. de 2023
Comentada: Panos Kerezoudis
el 1 de Jul. de 2023
Hi,
I have a long column vector ('trialnr', attached), whose elements are integer numbers from 1 to 55 (they index events in time-series).
I want to further concetenate the elements into groups (1-2, 3-4, 5-6, etc) so that I create blocks of rest-movement. The new vector will have the same size as the original.
Therefore, I want 1-2 to be 1, 3-4 to be 2 and so forth.
Any help would be great, thank you!
for example: if length(trialnr(trialnr==1)) is 7765 and length(trialnr(trialnr==2)) is 3548, then in the column vector these will be designated as 1 with length 7765+13548=11313.
1 comentario
Star Strider
el 26 de Jun. de 2023
I don’t see how this is going to work, since the ranges of the various elements (numbers of the individual elements) in the vector, although consecutive, are different —
LD = load('trialnr');
trialnr = LD.trialnr;
[Elements,Startidx,ic] = unique(trialnr, 'stable');
Lengths = diff([Startidx; size(trialnr,1)]);
LenvTable = table(Elements,Startidx,Lengths)
.
Respuesta aceptada
DGM
el 26 de Jun. de 2023
I'm not sure if this is what you're asking for, but:
V = [1 1 1 2 2 2 3 3 3 4 4 4 5 5 5]
V = ceil(V/2)
Más respuestas (0)
Ver también
Categorías
Más información sobre Lighting, Transparency, and Shading 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!