interpolate (extrapolate?) the values in between two matrices using existing data

1 visualización (últimos 30 días)
Hello all,
I have two matrices A and B that are plotted below:
A = [1, 2, 3, 4, 5; 0.3654, 0.3634, 0.3663, 0.3665, 0.3677];
B = [16, 17, 18, 19, 20; 0.4653, 0.4636, 0.4652, 0.4620, 0.4715];
figure; plot(A(1,:),A(2,:),'-o')
hold on; plot(B(1,:),B(2,:),'-o')
How can I use the y values of these two matrices to identify y values where X=6:15?
I know I can do this by finding the slope of the line between the average of vector A and average of vector B and then, populate the values in between. But I am curious to learn if there is a more precise way? Is there a modified version of interp1 that can serve this purpose?

Respuesta aceptada

VBBV
VBBV el 22 de Sept. de 2022
A = [1, 2, 3, 4, 5; 0.3654, 0.3634, 0.3663, 0.3665, 0.3677];
B = [16, 17, 18, 19, 20; 0.4653, 0.4636, 0.4652, 0.4620, 0.4715];
figure; plot(A(1,:),A(2,:),'-bo')
hold on; plot(B(1,:),B(2,:),'-bo')
C=[5:16];
V=interp1([A(1,:), B(1,:)],[A(2,:), B(2,:)],C,'spline')
V = 1×12
0.3677 0.3725 0.3805 0.3911 0.4032 0.4162 0.4291 0.4413 0.4518 0.4598 0.4646 0.4653
plot(C,V,'-bo')
You can include end points as @dpb suggested, and chose to modify the interp1 outputs by selecting appropriate method

Más respuestas (1)

dpb
dpb el 21 de Sept. de 2022
A = [1, 2, 3, 4, 5; 0.3654, 0.3634, 0.3663, 0.3665, 0.3677];
B = [16, 17, 18, 19, 20; 0.4653, 0.4636, 0.4652, 0.4620, 0.4715];
figure; plot(A(1,:),A(2,:),'-o')
hold on; plot(B(1,:),B(2,:),'-o')
C=[6:15]; C(2,:)=zeros(numel(C),1);
C(2,:)=interp1([A(1,end),B(1,1)],[A(2,end),B(2,1)],C(1,:));
plot(C(1,:),C(2,:),'-o')
To join the lines, incorporate A,B into the vector to evaluate for C, of course.
Can 'spearmint with various other interpolation schemes besides linear, of course, although with the toy data there's no real apparent connection between the two segments, one presumes this is just for show, not the real problem.

Categorías

Más información sobre Interpolation en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by