Calculating displacement many times with respect to different elements

2 次查看(过去 30 天)
I have the following data (or similar):
154240 1 7
154240 2 2
154240 5 6
154240 2 5
154240 6 7
154240 2 7
154240 5 6
154240 6 7
154240 4 6
154240 4 6
154240 4 6
641224 2 3
641224 2 1
641224 2 3
641224 1 2
641311 5 5
641311 7 5
It represents data of the form [tag number of rat, x coord, y coord] (as im studying a rat population). I would like to calculate the displacement of x & y with respect to the first x & y entries for each of the same value of the tag, i.e. I want an nx3 matrix (where n is size of my data) which gives me [tag number again,(0,x2-x1,x3-x1,x4-x1 etc),(0,y2-y1,y3-y1,y4-y1 etc)] but I am totally inept at programming and am flummoxed right now.
Any help is greatly appreciated!
  1 个评论
Sean de Wolski
Sean de Wolski 2013-1-28
So what output do you expect for you above input? Please describe to us how you get that. Results are worth a 1000 words!

请先登录,再进行评论。

回答(1 个)

Azzi Abdelmalek
Azzi Abdelmalek 2013-1-28
X your array
out=bsxfun(@minus,X,[0 X(1,2) X(1,3)])
  1 个评论
Timothy Russell
Timothy Russell 2013-1-29
This is great, but I the first x & y displacement for each different tag number needs to be (0,0) (as the displacement for the first time a rat is captured is (0,0)), and this isn't doing that. Is there an easy way to split up a matrix into seperate matricies by using the element in the first column (i.e. the tag number in this case)? Thanks though, it does what I wanted, I just haven't sort my data out properly yet!

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Shifting and Sorting Matrices 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by