How to do interpolation function to subtract 2 arrays

7 ビュー (過去 30 日間)
Yi Jie Teh
Yi Jie Teh 2016 年 4 月 15 日
コメント済み: Yi Jie Teh 2016 年 4 月 16 日
Hi guys, currently i have two sets of data i got from my pictures showing the original beam and deflected beam. And Im stuck as i was instructed to subtract the array of the original beam from the deflected beam profile. And i was told to use the interp1 function to do so yet, i rarely use matlab so i don't really know how to start with my question. Can anyone give me some clue? The data i got are only coordinates from the pictures. Thanks very much. And both my data got different numbers of points. And i was also asked to plot the deflection versus horizontal distance graph.

採用された回答

J. Webster
J. Webster 2016 年 4 月 15 日
編集済み: J. Webster 2016 年 4 月 15 日
You have two sets of (x,y) coordinates that represent the beam paths. Now if they two sets shared the same x coordinates, finding the difference in the paths would be as simple as subtracting corresponding y points
ydiff = y2-y1;
But if the x coordinates for the two data sets are different, you cant just do that because, for example, you can't subtract the y value for x = 1.5 cm from the other beams value that might be at 1.7 cm.
So you have to take one data set and estimate what its values would be if it had the same x values as the other. That's what the interp1 does
Vq = interp1(X,V,Xq)
X and V are the arrays containing the coordinates of one beam, Xq is an array containing the x coordinates of the OTHER beam, and Vq is the interpolated Y values that line up with the first x coords that you can use to find the difference.
say you have two data sets 1 and 2 with coordinates in arrays X1 Y1 and X2 Y2. If X1 is not identical to X2, then to find the difference...
X1 = [1 3 5 7 9];
Y1 = [10 14 18 22 26];
X2 = [2 4 6 8 10];
Y2 = [14 20 26 32 38];
Yint = interp1(X1, Y1, X2);
difference = Y2-Yint;
plot( X1,Y1,'-o', X2,Y2,'-o', X2,difference,'-o');
  1 件のコメント
Yi Jie Teh
Yi Jie Teh 2016 年 4 月 16 日
Cool budz, Thanks a lot. Will try on that!

サインインしてコメントする。

その他の回答 (0 件)

Community Treasure Hunt

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

Start Hunting!

Translated by