Hist3, Sort, and Finding Equal Matrices (any speed improvements/tips?)

1 view (last 30 days)
Michael
Michael on 20 Jan 2016
I'm simulating event positions and times, and histogramming then in the XY plane. I want to find for each event, the time difference to the next event in the same bin. I feel liek this should be a ~4 liner or so...
posXY = rand(nEv,2)
times = rand(nEv,1)
posBin = [2 2]; % put the events on a 2x2 mesh in X-Y plane
[hitMatrix, ~] = hist3(posXY, posBin);
then I want to find (for each event, in a given bin--I made four bins!) the time the next event occurs in that position bin. So i thought about sorting the events by their times, and using the indices to pick out the correct events that also occur in the same bin... making a logical and looping over events.. but I can't quite nail the whole sequence down.
I thought about using hist3 on every element to find which bnin in (x,y) it's at (which might be tedious or slow for large event numbers) and then finding equal matrices--same position, sorting those events in time and finding diff(times) and concatenating all those difference in collection times on every bin on the mesh and then histogramming those results using maybe histc(dTimes, saveTimes)...
Do you have any tips? Where Am I going wrong.. it seems like my answer is way too complicated and not really straightforward.. What's the best organization/execution?
I appreciate your input, Michael B.

Answers (0)

Community Treasure Hunt

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

Start Hunting!