Hi Josh,
Thank you for your input.
I managed to find and fix the issue, hopefully for good.
I identified a faulty circuit that lead to generating signals for Ports 1 and 2 at high frequency all throughout the trials. As a result Port1In, Port1Out, Port2In and Port2Out were quite long vectors, which significantly slowed down the addition of RawEvents to the Data .mat file ( BpodSystem.Data = AddTrialEvents(BpodSystem.Data, RawEvents);
).