MATLAB Answers

0

Interpolate among Datasets so one set matches the other

Asked by Stelios Fanourakis on 29 Oct 2019
Latest activity Commented on by the cyclist
on 1 Nov 2019
Hi
I have two datasets with different dimensions. Needs to be matched somehow and one dimension needs to be interpolated to fit the dimension of the second data set
My first dataset is X,Y (2D) and my second dataset is only Y (1D). I need to somehow combine those two datasets. Like trying to plug in the Y axis data from the second dataset to the first set which is 2D. So, the X axis from the first set will be interpolated to match the data of the new Y axis data (second set). Am I clear?

  2 Comments

When you say "datasets" do you mean the actual MATLAB dataset variable type? If not, how are your data stored? Can you upload a MAT file with the actual data (or a small, representative sample)?
Datasets are two different excel files. Both they have the same X axis but are changed in Y axis. I want to plug in the Y values of the second set to the first one and interpolate. E.g. if the Y values are in Newtons and there are thickness changes of a material vertically (compressive forces) for every X there is a Y value (Newton) caused the deformation or the change in thickness (shape). For different Y values (second set of excel data), needs to interpolate the appropriate forces.

Sign in to comment.

1 Answer

Answer by the cyclist
on 30 Oct 2019

% Data from your file that has both x and y
x1 = [2 3 5];
y1 = [1 2 3];
% Data from your file that has only y
y2 = [1.5 2.5];
% Interpolate the set of x data in based on the above.
x2 = interp1(y1,x1,y2)
Here is a simple example using the interp1 function. I'm not certain if this is what you mean.
If you look at that documentation page, note that the use of "x" and "y" variables are swapped compared to what is written here, because the normal convention is that y is dependent on x, but that is not what you have described in your question.
If this doesn't do what you want, or if it is unclear, then I suggest you actually load your data from Excel into MATLAB, save to a *.mat file, and upload those data here.

  7 Comments

Still a little unclear, and still no data to look at.
Are you saying that the value of X doesn't matter to the calculation? Can you simply interpolate force from strain (y), using the formula I posted?
yes actually x is stable. X is the lenght of the object and it stays the same since the force is vertical and compressive. So only y values are changing and the force vector which may be considered as the third variable. So, you suggest me to interpolate among y and forces and keep x stable. I will consider that one. Thanks again. If possible provide me a code. Thanks
% Data from your file that has both force and y
force1 = [2 3 5];
y1 = [1 2 3];
% Data from your file that has only y
y2 = [1.5 2.5];
% Interpolate the set of force data in based on the above.
force2 = interp1(y1,force1,y2)
Same as I posted above, but I've just changed variable names since you are interpolating force from y.

Sign in to comment.