ignoring error whilst running a timer
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
AA
el 22 de Feb. de 2015
Respondida: Guillaume
el 23 de Feb. de 2015
T = timer('Period',400,... %period
'ExecutionMode','fixedRate',... %{singleShot,fixedRate,fixedSpacing,fixedDelay}
'BusyMode','drop',... %{drop, error, queue}
'TasksToExecute',inf,...
'StartDelay',0,...
'TimerFcn',@(~,~)Untitled(q,a,norbert),...
'StartFcn',[],...
'StopFcn',[],...
'ErrorFcn',[]);
start(T);
Error while evaluating TimerFcn for timer 'timer-1'
Invoke Error, Dispatch Exception: Source: Microsoft Excel Description: Open method of Workbooks class failed Help File: xlmain11.chm Help Context ID: 0
I get the above error from time to time with the above matlab timer function. I suppose it is because the function Untilted reads an excel file which is not saved properly and then matlab starts to read the excel file. If I run the function again then the file is read properly and gets executed without error. My question: How can I run the timer above without stopping when there is an error, I need the time to continue even if there is an error.
0 comentarios
Respuesta aceptada
Guillaume
el 23 de Feb. de 2015
The normal way to ignore errors is to put a try ... catch around the statement that can potentially give an error, since the best place for that would be in your so descriptively named Untitled function, around the code that tries to open the excel file.
function Untitled(q, a, norbert)
%... some code
try
excel.Workbooks.Open(...)
catch
%failed to open
return;
end
%... rest of the code
end
0 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Code Execution en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!