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.

 채택된 답변

Star Strider
Star Strider 2022년 5월 16일

0 개 추천

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

Ilan
Ilan 2022년 5월 16일
I realize that my question was not accurate enough:
I would like to create a 3D matrix in which each pixel (x,y) will contain the number of time occurences (say f) for that pixel. For example, the outcome from the example above should be for pix 1,3 time=2:
(x, y, f, t) 1, 3, 2, 2
for pix 4,5, t=1: 4, 5, 2, 1
for pix 4,5, t=1.2: 4, 5, 1, 1.2
I hope it is clear now.
Thanks.
I hope it is clear now.
Not really. I have no idea what result you want.
I was going by: ‘Duplicate times for the same pixel should be summed.
My code does exactly that.
EDIT — (16 May 2022 at 21:36)
To collect them together in cells is straightforward —
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){xyt(x,:)})
Out = 7×1 cell array
{3×3 double } {[4 5 1.2000]} {2×3 double } {3×3 double } {[1 3 2.1000]} {[1 3 2.3000]} {[1 3 2.4000]}
Out{1}
ans = 3×3
4 5 1 4 5 1 3 4 1
Out{3}
ans = 2×3
4.0000 5.0000 1.4000 3.0000 4.0000 1.4000
Out{4}
ans = 3×3
1 3 2 1 3 2 3 4 2
.
Ilan
Ilan 2022년 5월 17일
Thanks, this is what I wanted.
Star Strider
Star Strider 2022년 5월 17일
As always, my pleasure!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

질문:

2022년 5월 16일

댓글:

2022년 5월 17일

Community Treasure Hunt

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

Start Hunting!

Translated by