MATLAB: Nonlinear interpolation without regression

average of plotsinterpolationMATLABplotpolyfitpolyval

I have two sets of testresults, for the same test. I wish to plot them in the same figure, together with an average of the two.
  • The test data doesn't fit any polyfit polynomia well.
  • The two datasets doesn't contain the same x-values.
Below is a simplified example:
% Testdata 1
x1 = [152 218 522 571 670 720 770 820 919 969 1168 1218 1268 1318 1368 1418 1468 1519 1569 1619 1669 1719 1750 1753 1757 1760 1764 1766 1770 1773 1776 1779 1782 1785 1788 1794];
y1 = [117 120 120 119 119 118 118 117 117 116 116 117 118 120 123 126 131 138 147 156 163 150 117 112 106 101 94 88 81 73 67 59 51 43 34 16];
% Testdata 2
x2 = [152 155 194 244 295 345 395 445 497 547 593 650 694 749 796 847 897 1147 1197 1247 1297 1347 1397 1447 1498 1548 1598 1648 1698 1746 1787 1798];
y2 = [117 115 115 112 112 112 111 111 107 108 107 107 108 109 107 109 107 107 108 109 111 113 117 121 127 134 142 148 142 109 36 4];
figure % Create plot
hold on; grid on
plot(x1,y1);
plot(x2,y2);
Is there a way to create a plot/ line between the two (a mean) without creating a regression?
The progam should be automated since I have approx 100 datasets.
Context: It's a torque/speed curve for electric motors, deccelaritng and accelerating.

Best Answer

I figured how to use the interp1 correctly.
figure % Create plot
hold on; grid on
plot(x1,y1);
ylim ([0 180])
plot(x2,y2);
xq = 155:5:1800; % X-values for interpolation
vq1 = interp1(x1,y1,xq); % interpolation for testdata 1
vq2 = interp1(x2,y2,xq); % interpolation for testdata 2
plot(xq,vq1) % interpolation plot for testdata 1
plot(xq,vq2) % interpolation plot for testdata 2
plot(xq,(vq1+vq2)/2) % plot the mean of the two interpolations