How to do interpolation function to subtract 2 arrays
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Yi Jie Teh
am 15 Apr. 2016
Kommentiert: Yi Jie Teh
am 16 Apr. 2016
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.
0 Kommentare
Akzeptierte Antwort
J. Webster
am 15 Apr. 2016
Bearbeitet: J. Webster
am 15 Apr. 2016
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');
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Interpolation finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!