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

조회 수: 2(최근 30일)
Corinne Gard
Corinne Gard 2019년 9월 3일
댓글: Corinne Gard 2019년 9월 3일
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

채택된 답변

darova
darova 2019년 9월 3일
편집: darova 2019년 9월 3일
Use interp1()
x0 = ...
y10 = interp1(x1,y1,x0);
y20 = interp1(x2,y2,x0);
y10 - y20

추가 답변(0개)

Community Treasure Hunt

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

Start Hunting!

Translated by