How can I subtract 2 2D graphs made by vectors of different length?

18 views (last 30 days)
I have 2 sets of data from the same experiment recorded with different methods. The results are 2 graphs describing the same but with some differences. To find those differences I want to subtract the graphs so that I can have a visual representation of where the differences are located.
The problem I have is that the first method has a "X resolution" of 10 data points per second, but the second method's resolution is not constant, sometimes its 7, sometimes its 15. Because of this I can’t just subtract the arrays, since they are not the same length.
Is there a way to do this?

Accepted Answer

Image Analyst
Image Analyst on 6 Jun 2018
Yes, just use interp1() to interpolate them to a common time sequence. If you can't figure it out, attach your two vectors in a .mat file, say what you want the new sampling spacing to be, and someone will do it for you.
  1 Comment
Ricardo Fuertes
Ricardo Fuertes on 6 Jun 2018
Thanks! Its works. I had to remove some data points with the same X value, otherwise I would get 'The grid vectors must contain unique points.' error.

Sign in to comment.

More Answers (1)

Alfonso
Alfonso on 6 Jun 2018
If you want to quantify the "difference" between 2 datasets of different length, say dataset A with length 100 and dataset B with length 150, you can interpolate the x and y coordinates of dataset A using the "interp1" function to 150 points (length B), then you could for example, calculate the RMSE between the 2 datasets to quantify the differences. (This is one of the ways you could do it)

Community Treasure Hunt

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

Start Hunting!