MATLAB: Issue with audioplayer/sound functions

audioplayerMATLABmulti-threadnon-blocking function callsound

Hi all,
I am running an automated test using Matlab. I have two functions, collectData and Analysis and a main script than calls these functions in that order. collectData plays a bunch of wav files using sound (also tried audioplayer) function (non-blocking function call) sequentially, make some measurements while the audio is being played to collect raw data. Analysis function analyses this data to generate results. The issue is that, sometimes Analysis function is called when collectData has not finished its execution completely and then Analysis function complains because it does not have complete data. I am guessing that sound/audioplayer has something to do with this but not sure exactly what. Could someone help me out here?
Thanks in advance, Alok

Best Answer

Do you have return argument for your collectData function? If not, you could add one, for example CompleteFlag=collectData(). The point is, to make sure collectData() is completed. Although, it should be that way even you don't have return argument. It is called in sequence, right? One suggestion, maybe add "pause(SomeSeconds)" after the collectData() calls.