Jawad Chughtai
Jawad Chughtai

Reputation: 65

How to compute difference of each point of a data series from the first point?

i have signature time-series data for x-y coordinates as given below(for one file)...

  x     y
12200 9400 
12200 9400 
12200 9400 
12200 9400 
12200 9400 
12200 9400 
12200 9400 
12200 9400 
12200 9400 
12200 9400 
12200 9400 
12300 9400 
12300 9400 
12300 9400 
12300 9400 
12300 9400 
12300 9400
12300 9300 
12300 9300...

I would like to compute the (difference) x-y coordinates relative to first point of the series... Could anyone guide me how do i compute it in matlab? Any suitable function or piece of code? Thanks in advance.

Upvotes: 0

Views: 68

Answers (2)

Leporello
Leporello

Reputation: 658

I assume that your question is, starting from a set of points (x1,y1);(x2,y2);...(xn,yn) how to get (0,0);(x2-x1,y2-y1);...(xn-x1,yn-y1)

Quick solution: if a is a N-by-2 array containing your data, then

b=a; b(:,1)=b(:,1)-b(1,1); b(:,2)=b(:,2)-b(1,2);

If your question was about how to import the data from a CSV file or something else, it is completely different.

Upvotes: 0

Jonas
Jonas

Reputation: 74940

To subtract the first row from an entire array, use bsxfun:

A = [
12200 9400 
12200 9400 
12200 9400 
12200 9400 
12200 9400 
12200 9400 
12300 9400 
12300 9400 
12300 9400
12300 9300 
12300 9300]

differenceToFirstPoint = bsxfun(@minus, A, A(1,:));

%# to calculate the norm:
normOfDifference = sqrt( sum( differenceToFirstPoint.^2, 2));

Upvotes: 1

Related Questions