2016-11-24 82 views
0

我想收到一封電子郵件時,Matlab是在調試模式下,所以我嘗試了以下內容:接收郵件,如果MATLAB是在調試模式下

timerTic=4; % how often the timer checks 

timerHandle = timer(); 
timerHandle.startDelay = timerTic; 
timerHandle.Period = timerTic; 
timerHandle.ExecutionMode = 'fixedRate'; 
timerHandle.TasksToExecute = inf; 
timerHandle.TimerFcn = @CheckDebugMode; 


j=0; 
while t==0 
    j=j+1; 
end 

其中funcion是:

function CheckDebugMode(~) 
% Check if Matlab is in Debug mode 
if feature('IsDebugMode') 
    sendSSLmail('[email protected]','Matlab is in debug mode','Matlab is in debug mode') 
end 

t不存在,因此發生錯誤並且Matlab進入調試模式(如果錯誤處於活動狀態,則爲dbstop)。 功能('IsDebugMode')等於1,但我沒有收到郵件。

這是我第一次在Matlab中使用對象,所以我敢肯定代碼在某種程度上是錯誤的。 也許有人可以幫助我嗎? 在此先感謝

回答

0

您是否開始計時?

start(timerHandle) 

編輯我沒有測試過這一點,但我懷疑你有你的功能手柄和功能本身的問題。計時器參數傳遞給你的函數,所以你需要在你的代碼來接受,那麼:

function CheckDebugMode(varargin) 

或傳遞,然後停止:

timerHandle.TimerFcn = @(~,~)CheckDebugMode 
+0

其實都不是! 我開始它,但後來我收到以下錯誤: 評估定時器'定時器-7'的TimerFcn時出錯 輸入參數太多。 timerTic = 4; %定時器檢查的頻率 timerHandle = timer(); timerHandle.startDelay = timerTic; timerHandle.Period = timerTic; timerHandle.ExecutionMode ='fixedRate'; timerHandle.TasksToExecute = inf; timerHandle.TimerFcn = @CheckDebugMode; start(timerHandle) j = 0; 而t == 0 j = j + 1; 結束 –

+0

我剛剛在函數中添加了varargin。非常感謝您的幫助,現在它可以工作! –