Is there way to suppress the timer?
12 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Joe
el 5 de Mayo de 2013
Comentada: Walter Roberson
el 6 de Abr. de 2021
Hello, I am using tic and toc to measure the runtime of MATLAB's sort function for arrays of n lengths. In order to understand how the runtime increases with respect to how large n is I have plotted the runtime vs n. The thing is, it gets kind of troublesome to see MATLAB computing all the runtimes in the command window especially when n gets really large. Is there a way to suppress it like it was an output?
0 comentarios
Respuesta aceptada
Cedric
el 5 de Mayo de 2013
Editada: Cedric
el 5 de Mayo de 2013
Just use a ; at the end of the line with the toc:
>> tic ; pause(1) ; t = toc ;
Here there is no output for example, and I have to display the content of t to get the value..
>> t
t =
1.0018
I assumed here that you had to store the output of TOC in some variable in order to plot it, and therefore that if there is an output, it's because you don't terminate the line with ;. Now I realize that you might have tried something else where there is no output argument to TOC. In such case, TOC seems to assume that it has to display its time measurement, and it is not something that you can block with ;.
So you have to pick a case with no output from the following:
>> tic ; toc % No output arg => display.
Elapsed time is 0.000001 seconds.
>> tic ; toc ; % Same here indeed.
Elapsed time is 0.000002 seconds.
>> tic ; t = toc % Output arg => no display, but
% the line defines t without ;,
% so t is displayed.
t =
1.0266e-06
>> tic ; t = toc ; % Output arg => no display, and ;
% so t is not displayed.
>> tic ; [~] = toc ; % Same here with ~ so you don't
% have to define a variable name.
4 comentarios
Amir Pasha Zamani
el 6 de Abr. de 2021
I have almost the same problem , but not with displaying the time elapssed on the screen, but the computational time of my code.
In fact, I am running a code for 12 hours now. I once stopped it to check the duration of a loop inside it, so that I have an estimation of the time for the whole program.
I activated a tic in the begining and a toc at the end of the loop, and I got what I wanted to know, but now, tic is still on, and it is making my code very slow, after 12 hours.
So I just need to stop counting the time.
Is there a way to do that ? ? ? ? ?
Walter Roberson
el 6 de Abr. de 2021
If you pause the execution, and then define private/toc.m in the same directory
function toc(varargin)
end
then that might work. But if you get it wrong it might also cause an error, so you would have to be careful in your testing.
Más respuestas (1)
Micah Ackerman
el 30 de Oct. de 2016
Editada: Walter Roberson
el 30 de Oct. de 2016
Take a look at the following example and see if it helps. No need to just toc.
tic
%Summation
Dragonfly_data=load('dragonfly.dat');
Sum=0;
x=1;
while x<=100
Sum=Sum+Dragonfly_data(x);
x=x+1;
end
Sum; %Sum is suppressed, because the problem asks for the average.
%Average
Average=Sum/length(Dragonfly_data);
elapsedTime = toc;
fprintf('The average is %-0.3f Hertz.',Average)
fprintf('\nProblem 3 took %-.3f seconds to run.',elapsedTime)
1 comentario
Ver también
Categorías
Más información sobre Workspace Variables and MAT-Files 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!