How to compare data from two different data systems y1,x1 and y2,x2?

3 views (last 30 days)
Hello dear community,
I want to compare data from two different data systems y1,x1 and y2,x2.
First you see a plot:
The Values are (for example)
Red plot is a "Motor 1" Line and have y1,x1 values: (41,0.1),(40,0.2),(40,0.3),(41,0.4),(39,0.5),....,(42,n).
The cyan line/points are "Trajectory" Line and have y2,x2 values: (43,0.29),(40,0.38),(41,0,49),(40,0.78),....,(41,n).
I want to compare this values (with true positive/false negative methods) and have to find out, how far away is a y2 value from y1 value. The problem is, there are different x points, so how it is possible to analyze both data arrays?
Thank you very much in advice!
Sincerely yours, Nik

Answers (1)

Walter Roberson
Walter Roberson on 23 May 2020
You can use pdist2() to find the distance from each x1/y1 point to each x2/y2 point, and then use min() . Or you can use knnsearch to find the 1 point in x2/y2 that is closest toeach x1/y1 point.
But... then what?
Sometimes what people do in these kinds of situations is to interp1(x2, y2, x1) to find the value in x2/y2 that would be "predicted" for x1, and from there you can compare to the actual y1 value to make some kind of determination.
  1 Comment
Nik Rocky
Nik Rocky on 24 May 2020
Edited: Nik Rocky on 24 May 2020
Thank you very much for answer.
I want use an interpolation, but there are some problems.
First, there are 301 values in x1 and y1 and 997 values in x2 and y2. So, i decided to make:
y1_interpol = interp1(x1,y1,x2);
hold on
p8 = plot(x2,y1_interpol,'o');
x2(1:10,1)
ans =
0.1858
0.1858
0.2323
0.2323
0.2788
0.2788
0.3253
0.3253
0.3718
0.4183
Problems:
Values of x2 have no grid and some times there are two values behind each other (two y2 values to same x2 point). And x2 ends with 29,4 sek, x1 with 30.
Aims:
I want proof:
how much matching are frequencies of y1 and y2 in 30 sec with cases:
  1. if (y1 ~= 0 && (y1 - 10)*n < y2 < (y1+10)*n) %(n 1...10) % TRUE POSITIVE - y1 is here, y2 detect y1
  2. if (y1 ~= 0 && y2 ~= 0 && ~((y1 - 10)*n < y2 < (y1+10)*n)) % FALSE NEGATIVE - y1 is here, y2 detect wrong signal = no detection of y1.
  3. if (y1 = 0) && (y2 ~=0) % FALSE POSITIVE - y2 detect signal of y1 - there are no y1 signal in this time
  4. if (y1 ~= 0) && (y2 ~=0) % TRUE NEGATIVE - y2 detect no signal of y1 - there are no y1 signal in this time
Questions:
How can I extend a x2 values between 0 and 30 sek when the are no regular grid? (feel a holes)
x2(950:954,1)
ans =
29.2569
29.2569
29.3034
29.3034
29.3499
29.3888%new value
29.4288%new value
29.4688%new value
.......
30.0000%new value
How can I become a same grid for both systems?
I tryed allreade to create one array and interpolate both data
t_ref = 0:0.01:30;
t_ref = t_ref';
y1_interpol = interp1(x1,y1,t_ref);
y2_interpol = interp1(x2,y2,r_ref);
But y2_interpol cant be created (I think is of course of mutiple x2 values behind each other).
Thank you!

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!