Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to resample with interp1 in Matlab when input vectors are of different length
    primarykey
    data
    text
    <p>I have two variables in a .mat file here: <a href="https://www.yousendit.com/download/UW13UGhVQXA4NVVQWWNUQw" rel="nofollow">https://www.yousendit.com/download/UW13UGhVQXA4NVVQWWNUQw</a></p> <p>testz is a vector of cumulative distance (in meters, monotonically and regularly increasing)</p> <p>testSDT is a vector of integrated (cumulative) sound wave travel time (in milliseconds) generated using the distance vector and a vector of velocities (there is an intermediate step of creating interval travel times)</p> <p>Since velocity is a continuously variable function the resulting interval travelt times and also the integrated travel times are non integers and variable in magnitude</p> <p>What I want is to resample the distance vector at regular time intervals (e.g. 1 ms, 2 ms, ..., n ms)</p> <p>What makes it difficult is that the maximum travel time, 994.6659, is less than the number of samples in the 2 vectors, therefore it is not straightforward to use interp1. i.e.:</p> <p>X=testSDT -> 1680 samples</p> <p>Y=testz -> 1680 samples</p> <p>XI=[1:1:994] -> 994 samples</p> <p>This is the code I've come up with. It is a working code and it is not too bad I think.</p> <pre><code>%% Initial chores M=fix(max(testSDT)); L=(1:1:M); %% Create indices % this loops finds the samples in the integrated travel time vector % that are closest to integer milliseconds and their sample number for i=1:M [cl(i) ind(i)] = min(abs(testSDT-L(i))); nearest(i) = testSDT(ind(i)); end %% Remove duplicates % this is necessary to remove duplicates in the index vector (happens in this test). % For example: 2.5 ms would be the closest to both 2 ms and 2 ms [clsst,ia,ic] = unique(nearest); idx=(ind(ia)); %% Interpolation % this uses the index vectors to resample the depth vectors at % integer times newz=interp1(clsst,testz(idx),[1:1:length(idx)],'cubic')'; </code></pre> <p>As far as I can see there is one issue with this code: I rely on the vector idx as my XI for interpolation. Vector idx is 1 sample shorter than vector ind (one duplicate was removed).</p> <p>Therefore my new times will stop one millisecond short. This is a very small issue, and duplicate are unlikely but I am wondering if anybody can think of a workaround, or of a different way to approach the problem altogether.</p> <p>Thank you</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload