Borrar filtros
Borrar filtros

Calculating displacement many times with respect to different elements

2 visualizaciones (últimos 30 días)
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 comentario
Sean de Wolski
Sean de Wolski el 28 de En. de 2013
So what output do you expect for you above input? Please describe to us how you get that. Results are worth a 1000 words!

Iniciar sesión para comentar.

Respuestas (1)

Azzi Abdelmalek
Azzi Abdelmalek el 28 de En. de 2013
X your array
out=bsxfun(@minus,X,[0 X(1,2) X(1,3)])
  1 comentario
Timothy Russell
Timothy Russell el 29 de En. de 2013
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!

Iniciar sesión para comentar.

Categorías

Más información sobre Particle & Nuclear Physics 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!

Translated by