How to I generate continuous arrays from two arrays with different data points?
12 views (last 30 days)
Show older comments
I would like to take two different array data sets:
e.g.
x1 = [ 1 5 8 20 ];
y1 = [10 12 15 20];
x1 = [2 6 8 19 21];
y1 = [1.5 5.3 16 22];
I would like to take these and turn the y values into continuous arrays along the same x array (say x = 0:1:22). That way I can find approximately what measurements of y1 and y2 are at for say x=2 and do things such as calculate the percent difference. Please let me know if this is not enough clarification.
Thank you!
0 Comments
Answers (1)
the cyclist
on 2 Aug 2023
Edited: the cyclist
on 2 Aug 2023
Your question is not perfectly clear to me, but it sounds like you could use the interp1 function to interpolate each data set to a common set of x points.
x1 = [ 1 5 8 20 ];
y1 = [10 12 15 20];
x2 = [2 6 8 19 21];
y2 = [1.5 5.3 16 22 23]; % I changed this, because yours were not the same length
xq = 0:22;
y1q = interp1(x1,y1,xq)
y2q = interp1(x2,y2,xq)
There are NaN values because interp1 will not extrapolate by default. See the documentation for options.
See Also
Categories
Find more on Data Preprocessing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!