필터 지우기
필터 지우기

Can you make matlab do a beep every 5 seconds?

조회 수: 3 (최근 30일)
André Magrinho
André Magrinho 2016년 1월 4일
답변: Jan 2016년 1월 4일
I'm making a chronometer on Matlab and i'd like it to beep every 5 seconds so the user knew that 5 seconds have passed.. Is there a way to make it ? Thanks !

채택된 답변

Jan
Jan 2016년 1월 4일
This is a job for the timer:
TimerH = timer('Period', 5, 'ExecutionMode', 'fixedRate', ...
'Callback', @TimerCallback);
start(TimerH);
function TimerCallback(TimerH, EventData)
beep;

추가 답변 (1개)

goerk
goerk 2016년 1월 4일
i=0;
load gong.mat;
while i<1 %endless loop
sound(y);
pause(5);
end
It is also possible to use the 'beep' command instead of the gong (stored in y). Maybe it is more accurate if you use the the 'clock' function (then there is no drift dependent to the execution time).
load gong.mat;
while true %endless loop
sound(y);
lastTime = clock;
while etime(clock, lastTime) < 5
pause(0.01);
end
end

카테고리

Help CenterFile Exchange에서 Clocks and Timers에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by