COnvert x,y, time array into 3D matrix

1 visualización (últimos 30 días)
Ilan
Ilan el 16 de Mayo de 2022
Comentada: Star Strider el 17 de Mayo de 2022
Hello,
I have an array of events captured at different pixels at different times. Each row has x, y and time values.
Here a simple example (x, y, time) with a short list of events:
1, 3, 2
1, 3, 2.3
1, 3, 2
1, 3, 2.1
1, 3, 2.4
4, 5, 1
4, 5, 1.4
4, 5 , 1
4, 5, 1.2
3 , 4, 1
3, 4, 1.4
3, 4 ,2
As can be seen, some times are duplicates for the same x,y.
I would like to create a 3D matrix made of x,y slices arranged according to time.
Duplicate times for the same pixel should be summed.
I would appreciate any suggestion.

Respuesta aceptada

Star Strider
Star Strider el 16 de Mayo de 2022
Try this —
xyt = [1, 3, 2
1, 3, 2.3
1, 3, 2
1, 3, 2.1
1, 3, 2.4
4, 5, 1
4, 5, 1.4
4, 5 , 1
4, 5, 1.2
3 , 4, 1
3, 4, 1.4
3, 4 ,2];
[Uxytr,~,ix] = unique(xyt(:,3));
Out = accumarray(ix,(1:size(xyt,1))',[],@(x){[sum(xyt(x,[1 2]),1) unique(xyt(x,3))]})
Out = 7×1 cell array
{[ 11 14 1]} {[4 5 1.2000]} {[7 9 1.4000]} {[ 5 10 2]} {[1 3 2.1000]} {[1 3 2.3000]} {[1 3 2.4000]}
There are 7 unique times, and the (x,y) values for those times are summed, with the times themselves remaining unchanged.
.
  4 comentarios
Ilan
Ilan el 17 de Mayo de 2022
Thanks, this is what I wanted.
Star Strider
Star Strider el 17 de Mayo de 2022
As always, my pleasure!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Logical en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by