How can I reset the tic/toc timer?

13 visualizaciones (últimos 30 días)
Alexius Wadell
Alexius Wadell el 5 de Abr. de 2017
Respondida: Steven Lord el 5 de Abr. de 2017
How can I clear everything from the MATLAB workspace? clear all/classes/java does a pretty good job but it doesn't reset the tic/toc commands.
What I want is:
tic
commandThatClearsEveryting
toc %Throws error
More generically: How can I run a test script such that the code is effectively run in a newly opened MATLAB workspace?

Respuesta aceptada

Jan
Jan el 5 de Abr. de 2017
Editada: Jan el 5 de Abr. de 2017
Do not run it as if, but simply run is in a newly opened Matlab session:
system('matlab -r YourFunction');

Más respuestas (1)

Steven Lord
Steven Lord el 5 de Abr. de 2017
I'm not sure what you mean by resetting the tic and toc timer, but if you want to time code that may itself contain call to tic or toc, call tic with an output and pass that output into toc.
sumLoop = 0;
timeOverall = tic;
for k = 10:10:500
M = magic(k);
timeLoop = tic;
V = eig(M);
TL = toc(timeLoop);
sumLoop = sumLoop + TL;
fprintf('Calling EIG for a %d by %d matrix took %f seconds.\n', k, k, TL);
end
fprintf('The entire loop took %f seconds.\n', toc(timeOverall));
fprintf('Cumulative sum of loop timing is %f seconds.\n', sumLoop);
The timing data in the messages displayed by the last two lines should be very close to one another. They won't be identical, since the timing of the inner fprintf call is not included in sumLoop, but they should be reasonably close.

Categorías

Más información sobre Structures 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!

Translated by