Discretise into Equal Intervals

I have an array of data, 2 columns and 19 rows of entries, which can be plotted as a loglog curve. However, the x-data I have does not have standard intervals and I need to approximate the curve as a piecewise linear function. Any suggestions as to how to go about this?

6 Comments

Do you mean that the x-data is not aligned with your (2-by-19) array of data?
The x-data are increasing values from 0.005 - 2.13, taken straight from the first row of entries, but they do not have standard intervals. I'm able to plot the curve, but this curve I then need to discretise into equal intervals and apply a piecewise linear function over that interval.
So you would like to interpolate the values of the curve at regularly-spaced points?
What, precisely do you mean by "discretize over equal intervals"? If you mean to interpolate to a uniform (and is this uniform on linear or log axis) interval, just apply interp1 finding a new y for the chosen set of x on the log- or linear-spacing. Of course, by your description the fit is linear only in log-log so you'll want to transform first.
After that it should be relatively straightforward to choose breakpoints -- fit segments and move the breakpoint to minimize R-sq or max residual or whatever chosen criterion is.
Yes. Within x I was considering an interval of 0.07 to fit the data, as it isn't an increasing rate I couldn't make the function interp work as the interval was set, rather than a rate. Thanks so much for your help!
It works! Thank you so much Bruno and dpb. I was able to start messing with the interp1 function, I was using the wrong one beforehand with your suggestion dpb, and Bruno your answer clarified it from there.
Thanks for your help!

Sign in to comment.

 Accepted Answer

You can use several methods to interpolate data points from non-uniformly spaced points. There are listed here for one dimension:
Here is an example using interp1:
vq = interp1(c, v, xq)
where x are the (non-uniformly spaced) input points (the first row in your vector) with values v (the second row in your vector), and xq are the query points (your uniformly spaced points). The function returns the interpolated values at xq in the vector vq.
For uniformly-spaced query points, you can use:
x_begin = x(1,1); % your 0.005
x_end = x(end,1); % your 2.13
numPoints = numel(x(:,1)); % number of points in your original vector; you can change that
xq = linspace(x_begin, x_end, numPoints);
for numPoints linearly spaced between x_begin and x_end. If you prefer to specify the length of each interval instead of the number of points, you could write:
xq = x_begin : int_length : x_end;
with int_length = 0.07.

More Answers (0)

Products

Community Treasure Hunt

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

Start Hunting!