How to import multiple .xml files into Matlab for MSD analyze?

Dear all,

     I have generated several track files through TrackMate function "export tracks to XML file", and I can import them separately into Matlab to analyze the MSD, like:

    file_path_tracks = '1_Tracks.xml';
    tracks = importTrackMateTracks(file_path_tracks);

However, to generate a reasonable mean MSD, I need to combine all the tracks. I have tried the function of “merge a trackmate file” to merge all the track files and then export one combined track into Matlab. It turns out matlab have troubles to recognize the tracks and generate the error:

        Dot indexing is not supported for variables of this type.

        Error in importTrackMateTracks (line 121)
        t = str2double(detectionNode.getAttribute('t'));

I wonder is there a way from either trackmate or matlab to enable me to combine multiple tracks? I’m a total outsider to matlab. I would very appreciated if you can provide me a code, which I can combine to the msdanalyzer directly.

Best,
Meifang

1 Like

Hello @MEIFANG

Actually it is better to directly concatenate the tracks in MATLAB.
For instance if your physical units and frame interval are equal for all movies, you can do this:

t1 = importTrackMateTracks('1-FakeTracks_Tracks.xml', true, false);
t2 = importTrackMateTracks('2-FakeTracks_Tracks.xml', true, false);

% This concatenates the tracks:
t = [ t1 ; t2 ]

ma = msdanalyzer(2, 'µm', 's')
ma = ma.addAll(t)

% let's roll

Please let us know if it works for you.

1 Like

Dear Tinevez,

    Thanks a lot for the respond. I found that when I manually added points to a track or merged tracks to generate one track, the error in the following will happen: 

                Dot indexing is not supported for variables of this type.
                Error in importTrackMateTracks (line 121)
                t = str2double(detectionNode.getAttribute('t'));

      Therefore, I avoid any manual operation after the tracks were generated on the premise that divide or merge tracks are not allowed. And the function "merge a trackmate file" and later import to matlab works fine. 

      I will test your code in the further analyze and let you know whether it works.

Best,
Meifang

Hello @tinevez,
It worked for me, thank you so much!!!
Louisiane