How to I generate continuous arrays from two arrays with different data points?
5 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(1 个)
the cyclist
2023-8-2
编辑:the cyclist
2023-8-2
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.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Annotations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!