フィルターのクリア

Calculating displacement many times with respect to different elements

2 ビュー (過去 30 日間)
Timothy Russell
Timothy Russell 2013 年 1 月 28 日
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 Center および File ExchangeParticle & Nuclear Physics についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by