Interpolating non-strictly Monotonic data

3 次查看(过去 30 天)
Hello everyone!
Well, The situation I am facing is that:
I have two sets of data (which I have attached along as MS Excel files):
1. Ref Concentration v/s time (sheet1)
2. A1 values v/s Time (sheet2)
The data set number 1., has time interval of 2 min between readings. And dataset number 2., has time interval of 1 min (approx) between readings. What I want to do is interpolate the values of Ref concentration (Dataset no.-1) to specific time values of dataset no. - 2.
I tried using the function: {vq = interp1(x,v,xq)}. But the problem is x and v vectors, in my case (i.e- Reference concentration and Time) are non-strictly Monotonic increasing and thats why I get the error:
Error using griddedInterpolant The grid vectors are not strictly monotonic increasing.
Is there a way I can solve this problem?
  2 个评论
Matt J
Matt J 2015-2-2
Since you know your data is non-monotonic, isn't the obvious solution to make it so?
David Young
David Young 2015-2-2
Matt J is correct - you need to make the times monotonically increasing. This wouldn't be difficult, except that you have some repeated times which have different values of the ref concentration. For example, for time 23970 on row 10127 of sheet 1, the ref conc is 0.495711258, and for the same time on row 10157 the conc is 0.492291607. There are 30 such repeated times in the dataset.
To reach a solution, you need to define what you want to do about these anomalies. Possibilities include:
  • Delete all data for repeated times.
  • Average the two concentrations for each repeated time.
  • Add a time offset to all rows above 10157.
  • Adjust one of each pair of times by a small amount.
Choosing the right thing to do depends on understanding the circumstances which gave rise to these readings.

请先登录,再进行评论。

回答(1 个)

Star Strider
Star Strider 2015-2-2
编辑:Star Strider 2015-2-2
See if this does what you want:
filename = 'pramit Sood Data for Interpolation.xlsx';
[st, sh] = xlsfinfo(filename);
[d1, s1, r1] = xlsread(filename, sh{1}); % Read ‘Sheet1’
[d2, s2, r2] = xlsread(filename, sh{2}); % Read ‘Sheet2’
[d1u,ia1,~] = unique(d1(:,2)); % Get ‘unique’ ‘Sheet1’ Times
d1i = interp1(d1(ia1,2), d1(ia1,1), d2(:,2), 'linear', 'extrap');
figure(1)
plot(d2(:,2), d1i)
hold on
plot(d2(:,2), d2(:,1)*50)
hold off
The unique call finds the unique values in ‘Sheet1’ (that is causing the non-monotonicity problem), then uses those indices to select the values for interp1. The first plot call plots the interpolated ‘d1i’ values against the ‘d2’ time vector, demonstrating that the interpolation appears to have been correct. (The second plot are the ‘Sheet2’ data as imported. The multiplication by 50 simply makes it visible on the plot. It does not alter the original data.)
  1 个评论
David Young
David Young 2015-2-3
This represents the choice of discarding one of the two different concentration values recorded in the spreadsheet for duplicated times. For this to be the right way to deal with the problem, it's necessary to be certain that the times are all correct and one of the concentration values can be neglected. So although the solution solves the programming problem of getting something to work, it may be that the underlying problem needs addressing for the result to be scientifically valid.
See my comment on the question for other choices that might be made.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 MATLAB 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by