Interpolating non-strictly Monotonic data
4 views (last 30 days)
Show older comments
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 Comments
Matt J
on 2 Feb 2015
Since you know your data is non-monotonic, isn't the obvious solution to make it so?
David Young
on 2 Feb 2015
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.
Answers (1)
Star Strider
on 2 Feb 2015
Edited: Star Strider
on 2 Feb 2015
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 Comment
David Young
on 3 Feb 2015
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.
See Also
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!