Search code examples
matlabdifferencearray-difference

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.


Solution

  • 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));