Filter löschen
Filter löschen

How to treat x axis made of 2 data sets as continuous

2 Ansichten (letzte 30 Tage)
Corinne Gard
Corinne Gard am 3 Sep. 2019
Kommentiert: Corinne Gard am 3 Sep. 2019
I have 2 sets of flow data which I am plotting against one another in a validation test (one machine is validating the other). I have trimmed and scaled the data and they plot against one another nicely. I need to see whether the difference in y values between the plots is within error allowance at any given x value.
The complicated part is sampling rate of machines is different - one records exactly every 0.05 s and the other is meant to do the same but when you look at the data it varies +- 0.015s every sample
From a plotting perspective this is fine, I just use x1 and x2 with the same number of data points. However, now I don't have just one x scale (time) where I can say "at x_n, y1_n - y2_n = ". Comparison across the x1 and x2 arrays doesn't work because the data point with the same indice is not actually a recording at the same time.
Is there a way I can treat the x axis, time, as continuous such that at any given x I can extract the respective y values of my plot?
This is the relevent part of my function, where newFile holds both data sets in a matrix and x1 and x2 refer to the columns that hold the time data for each data set.
function variableCompare(obj)
seconds = 40;
int = seconds/obj.sam_rate;
x1 = obj.newFile{1:int,1};
x2 = obj.newFile{1:int,5};
%Flow comparison
figure(1)
y1 = obj.newFile{1:int,2};
y2 = obj.newFile{1:int,6};
plot(x1, y1)
title("Flow Comparison test")
xlabel("Time (s)")
ylabel("Flow")
hold on
plot(x2, y2)
legend({"FlowLab", "NALM"});
hold off
Here is the plot, which is good enough for what I need
flowcompare.PNG

Akzeptierte Antwort

darova
darova am 3 Sep. 2019
Bearbeitet: darova am 3 Sep. 2019
Use interp1()
x0 = ...
y10 = interp1(x1,y1,x0);
y20 = interp1(x2,y2,x0);
y10 - y20

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by