MATLAB: How to take the difference of y axis points at the same value of x-axis from 2 curve at the same graph

for loopgraphinterpolationplot

Hi,
I am struggling to take a difference between 2 y axis points at the same x axis value from 2 curve.
1st Curve:
x = [20,30,40,50,60,70,80,90,100]
y = [260,350,470,610,625,675,695,750,800]
%Plotting the points on the graph
plot(x,y,'x','LineWidth',3)
line (x,y,'Color','k','LineStyle','–','LineWidth',1)
hold on
2nd Curve:
for i = 2:length(q)
Q = q(i) ;
if h(i-1) < h1
v_2 = ((Q/1000) / Area_Outlet1);
h(i) = 75+((1 / (rho * g)) * (Patm2 – Patm1 + 0.5 * rho * (v_2^2 – v_1^2)) + h_f)*1000
else
v_2a = ((Q/1000) / Area_Outlet2);
h(i) = 75+h1 + ((1 / (rho * g)) * (Patm2 – Patm1 + 0.5 * rho * (v_2a^2 – v_1^2)) + h_f)*1000
end
end
plot(q,h)
hold off
Second curve plotted by using the loop. I want to find out what are the y-axis points at x = [20,30,40,50,60,70,80,90,100] for both curves.

Best Answer

You can use interp1()
h_new = interp1(q, h, x); % h_new are values at q=20,30,40,...,100