How to I generate continuous arrays from two arrays with different data points?
10 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Risposte (1)
the cyclist
il 2 Ago 2023
Modificato: the cyclist
il 2 Ago 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.
Vedere anche
Categorie
Scopri di più su Data Preprocessing in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!