Interpolate among Datasets so one set matches the other

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.

Answers (2)

% 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.

9 Comments

Actually no it is not so simple. I need to think a bit more and come back with additional information. A simple interpolation will not do what I want since the X,Y values are actually a 2D shape that corresponds to certain force values for every X,Y pair. Means, that the force values needs to be interpolated while the X,Y pair changes. The X (length of an object) is the same at both datasets but the Y values that denotes the height of the object changes. So, based on the y changes the forces needs to be interpolated.
It's actually like a conditional. E.g. If y = 3 mm then Force = 5 Newton, what if = 2.5 mm?? How much force?
It is unclear to me if x is a function of y, or if there is some third variable that is a function of x and y.
Again, I suggest you upload your data if possible. Also, a small thing that might actually help is to use descriptive variable names (e.g. distance and force instead of y and x). You'd be surprised at how much that can sometime help in creating the correct algorithm.
I have x data which is the length of an object. Y data which is the height or the object's thickness. X data is same for both sets. Y axis data are different among sets. There is a third variable that is linked to y values. Y values are strain, 3rd variable is force and X is length of the object. Based on y values the force is changing. So different y values need to interpolate force values.
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.
if x1 = [-3 -2 -1 0 1 2 3 4];
y1 = [9 4 1 0 1 4 9 16];
y2 = [8];
how we can calculate "x2 = interp1(y1,x1,y2)".
i.e. here we will get two values of x1 correspond to single value of y2. pls explain to it.
thanks
You should really open a new question, rather than burying this as a comment on an 8-month-old question.
But, since I happened to see it ...
You'll need to separate your problem into two different "branches" of y, because the sample points must be unique. So, you'll need to do one interpolation with, for example, the values of y>=0, and another with y<0.

Sign in to comment.

Thanks for your response.
Actually my problem is to find the fwhm(s) of large number of curve like following. So i require the interpolation values of x corresponding to average y values to write the code (because x values do not lie exactly y data points in average of y) . There are exist two values of x correspondinfg to single average value of y in a one curve (therfore sample point is not unique).
i looking forwrd.
Thank YOU.

1 Comment

but you still posted your question here, as an answer to Stelios's question. Why?
We look forward to answering your question when you post it as your own question, not here in Stelios's thread. In the meantime, check out the find() function, like index=find(signal < threshold).

Sign in to comment.

Categories

Find more on MATLAB in Help Center and File Exchange

Asked:

on 29 Oct 2019

Commented:

on 26 Jul 2020

Community Treasure Hunt

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

Start Hunting!