Reputation: 113
I have a problem with interpolating.
the plot of the points is here.
If we zoom in , the plot looks something like this this.
I do not know how to use the Matlab interp1 function to interpolate this.
Explanation:
This is a space time diagram, i.e. the x axis is the space and the y-axis is the time.
Hence, the structure of the vectors x and y is as follows:
The vector y is defined as
y=(1,1,2,2,3,3,4,4,...,2500,2500)
and the x-vector contains (pairwise) the positions, i.e.
x(i)
and x(i+1)
are the different positions at time y(i)=y(i+1)
.
I think the problem maybe is that at different times, we have the same points as can be seen in the zoomed in picture above.
How many time-steps the x-values remain the same differs, sometimes they remain the same for 3 time-steps, sometimes even for 4 time-steps, sometimes only for 2 time-steps.
Upvotes: 1
Views: 139
Reputation: 12214
You can use acccumarray
to perform some operation on the values in Y
that correspond to each unique value of X
.
Using some example data:
x = [1, 1, 2, 2, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 7, 7, 7, 7, 8, 8, 8];
y = 1:length(x);
We get something like the following:
Now use accumarray
to perform some calculation on each cluster:
clusteravg = accumarray(x', y, [], @mean);
clustermax = accumarray(x', y, [], @max);
clustermin = accumarray(x', y, [], @min);
The first input to accumarray
is an array of subscripts, the second input is an array of values that correspond to those subscripts. accumarray
collects all of the elements of the second input that share the same subscript (first input) and performs the specified calculation on them. Here I've calculated the average, max, and min for each cluster of values:
Yay
Upvotes: 1