@msdanalyzer matlab class - drift corrected trajectories

Hello everyone,

I am using the @msdanalyzer matlab class to look at my single particle track data. It is a fabulous class that makes analysis of trajectories so easy and straightforward!

I have a small query regarding the drift correction. is there a way to get the drift corrected trajectories as an output? I am able to get the drift corrected MSD of the trajectories, and there is another set of data called ‘ma.drift’. What exactly is saved inside the ma.drift?

My idea is to take the drift corrected trajectories (x,y,z coordinates with time) and further analyze and take a look at possible change points in the tracks.

Thank you very much
Z

Hi @Zara12345,
I have not used that class but may be you can try to align the stack before doing tracking, in this case your trajectories will come already corrected…?
Ilya

Thanks for you kind words @Zara12345!

I think that the field ma.drift does what you want.
Looking at the code (https://github.com/tinevez/msdanalyzer/blob/master/%40msdanalyzer/computeDrift.m) you can see that the calculated drift is stored there in the shape of [ time coords ]:

% Results are stored in the 'drift' field of the returned object.
% It is a double array of size N x (nDim+1) (nDim being the problem
% dimensionality), and must be arranged as following: [ Ti Xi Yi ... ]
% etc. If present, it will by used for any call to computeMSD and
% computeVCorr methods.

 obj.drift = [time ldrift];

After that you want to use it to correct trajectories. For instance, in the computeMSD code you can find the following:


    track = obj.tracks{index};
    t = track(:,1);
    t = msdanalyzer.roundn(t, msdanalyzer.TOLERANCE);
    X = track(:, 2:end);

    % Determine drift correction
    if ~isempty(obj.drift)

        tdrift = obj.drift(:,1);
        xdrift = obj.drift(:, 2:end);

        % Determine target delay index in bulk
        [~, index_in_drift_time, index_in_track_time] = intersect(tdrift, t);
        % Keep only track times that can be corrected.
        X = X(index_in_track_time, :);
        t = t(index_in_track_time);
        % Subtract drift position to track position
        X = X - xdrift(index_in_drift_time, :);
        
    end