Using Interp1 - monotonic increasing values

6 Ansichten (letzte 30 Tage)
Monty
Monty am 14 Mär. 2014
Bearbeitet: Walter Roberson am 11 Jul. 2015
Hi
I am trying to interpolate physiological values for a study I have run - values for blood pressure, HR and saturations.
I have created a text file and trying to use a script I have used before to run the interpolation.
Text file is:
0 101 51 98 71
5 0 0 97 71
10 103 50 97 73
15 0 0 98 72
20 93 51 98 73
25 0 0 98 73
30 95 52 98 73
35 0 0 98 72
40 94 50 97 73
45 0 0 97 73
50 97 55 97 69
55 0 0 98 60
60 87 51 98 61
65 0 0 98 61
70 89 50 98 60
75 0 0 98 61
80 92 54 98 61
85 0 0 97 61
90 91 51 98 62
95 96 56 98 64
100 0 0 98 64
105 94 54 98 61
110 0 0 98 60
115 95 51 97 60
120 0 0 98 61
125 99 54 98 61
130 0 0 98 61
135 93 52 97 61
140 0 0 98 61
145 92 50 98 61
150 0 0 98 62
155 92 57 97 65
160 0 0 98 65
165 94 50 97 67
170 0 0 98 65
175 95 57 98 69
180 0 0 98 64
185 94 50 98 59
190 0 0 98 53
195 95 57 99 52
200 0 0 98 63
205 98 59 98 58
210 0 0 97 59
215 97 59 97 64
220 0 0 98 64
225 98 50 98 64
230 0 0 99 64
235 98 59 97 65
240 99 66 98 64
Script is:
close all
clear all
A = load(uigetfile());
time = A(:,1);
SBP = A(:,2);
DBP = A(:,3);
sats = A(:,4);
hr = A(:,5);
x = SBP;
y = time;
start=min(time);
finish=max(time);
xi=(start:0.001:finish);
yi=interp1(x,y,xi,'linear');
But getting error:
Error using griddedInterpolant
The grid vectors are not strictly monotonic increasing.
Error in interp1 (line 191)
F = griddedInterpolant(X,V,method);
Error in interpolate_lab_values (line 34)
yi=interp1(x,y,xi,'linear');
Have tried everything I can think of and find on the net but no luck
Thanks loads!
  3 Kommentare
nl2605
nl2605 am 14 Mär. 2014
Did you try changing the method?
Monty
Monty am 14 Mär. 2014
Yup - same with spline/nearest

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

John D'Errico
John D'Errico am 14 Mär. 2014
I think you misunderstand interpolation.
Given your data, you tried to do this:
time = A(:,1); SBP = A(:,2); DBP = A(:,3); sats = A(:,4); hr = A(:,5);
x = SBP; y = time;
start=min(time); finish=max(time);
xi=(start:0.001:finish); yi=interp1(x,y,xi,'linear');
I assume that time is what it says, the time you took a sample at, and that SBP is a blood pressure at that time.
[time,SBP]
ans =
0 101
5 0
10 103
15 0
20 93
25 0
30 95
35 0
40 94
45 0
50 97
55 0
60 87
65 0
70 89
75 0
80 92
85 0
90 91
95 96
100 0
105 94
110 0
115 95
120 0
125 99
130 0
135 93
140 0
145 92
150 0
155 92
160 0
165 94
170 0
175 95
180 0
185 94
190 0
195 95
200 0
205 98
210 0
215 97
220 0
225 98
230 0
235 98
240 99
Interpolation allows us to take a function of some variable x, and predict a variable y(x), given a set of points (x,y). The function MUST be single valued at any location x, else how can one unambiguously compute y(x)?
Perhaps you see the problem. You are apparently trying to treat SBP as the independent variable x, and time as the dependent variable x. This makes NO sense at all physically, since you appear to have sampled the blood pressure as a function of time. Here time is the independent variable.
Of course, interp1 gets upset, because you have MANY replicate values for SBP. I have no idea what the meaning of those zeros is, but surely it makes no sense to try to predict time as a function of SBP!
Perhaps your goal was to predict SBP(time). This makes sense, since you compute a start time and an end time for the interpolation. However, interp1 cannot know what you WANT to do, only what you TELL it to do! Computers are only capable of reading your mind in the sci-fi shows.
Even then, I think it makes no real sense to try to interpolate this as a function of time, unless you appreciate that the zeros are surely meaningless.
So finally, IF I had to guess, what you really wanted to do is to interpolate SBP(time) but without those spurious zeros in the data. The crystal ball (even MY crystal ball) is foggy though.
  6 Kommentare
John D'Errico
John D'Errico am 17 Mär. 2014
LOOK at your data. Read the error message. Think about what it is telling you. Don't just give up.
time'
ans =
Columns 1 through 22
0 5 10 15 20 25 30 35 40 45 50 55 60 65 70 75 95 85 90 95 100 105
Columns 23 through 44
110 115 120 125 130 135 140 145 150 155 160 165 170 175 180 185 190 195 200 205 210 215
Columns 45 through 49
220 225 230 235 240
>> diff(time')
ans =
Columns 1 through 22
5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 20 -10 5 5 5 5 5
Columns 23 through 44
5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5
Columns 45 through 48
5 5 5 5
You should see that the time vector is not an increasing sequence, something that interp1 needs. I'm not sure why it is that your sampling times vary like this. Perhaps you are a sloppy typist. Perhaps there is a local time warp in your vicinity. Perhaps your experiment was run on the deck of the starship Enterprise at an inopportune time. Have you recently traveled faster than light? Faster than sound? Faster than a rubber chicken on steroids?
Regardless, you need to correct the problem to be able to use interp1. Proper use of the function sort may be all it takes, or maybe you just need to be more careful about how you enter your data.
Monty
Monty am 17 Mär. 2014
Great - thanks loads!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

nl2605
nl2605 am 14 Mär. 2014
Ohh I see now. Many of your data points are the same and not monotonically increasing or so.
Perhaps this will help. 'unique' function will omit the repeated values. But all the data points are equally important for you I guess?
Then maybe 'griddatan' would work for you.
  2 Kommentare
Monty
Monty am 14 Mär. 2014
Thanks - have tried that and it needs X to have two columns.... any ideas?
John D'Errico
John D'Errico am 14 Mär. 2014
griddatan does NOT work with replicates.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Data Import and Analysis finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by