How do I delay a function ?

Hi, I really need some help with this project. I am making a sequence of frequencies and they are all playing at once when I run the script. I need a way to delay or stop each function so that each function doesn't go until the the preceding one finishes. Thanks. -Thomas

2 个评论

It sounds like these are callback functions, or something similar. Without seeing your code it is impossible for us to know how you are calling these functions. You can upload your code editng your question, clicking the paperclip button, and then clicking both the Choose file and Attach file buttons.
Okay, thank you for the instructions. Sorry, I am a little new to this.

请先登录,再进行评论。

回答(1 个)

Thomas - you may want to consider using the audioplayer object to play your audio data as it has the playblocking function call which will play the audio and block (or hold control) until the playback completes (so subsequent lines of code will not execute until the audio has fully played). For example, we can replace your
sound(y);
call with
player = audioplayer(y,Fs);
playblocking(player);
where Fs is the sampling rate (which appears to be 10000 for many of your "notes" to the Star Wars theme). Try integrating the above into your code and see (or hear) what happens!

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by