From the following vector:
depth = [0:0.1:20];
How could I create a new vector that had the same data as ‘depth’ but a value taken every 0.5, providing an outcome of:
d2 = depth(1:5:end);
Since my data is not actually spaced at 0.1 intervals but at random intervals I cannot apply the simple approach shown above. What would be the best methods of achieving this?
If you want to find the closest points in the array to a linearly spaced grid, you can do it like this:
Note that entries in
indsmight be repeated. Otherwise, if you want to do an interpolation in your vector, you needinterp1. From the documentation:Note that multiple different interpolation kernels are available, e.g.,
'linear','spline', etc. Consulthelp interp1for more info.