Is there way to suppress the timer?

11 次查看(过去 30 天)
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?

采纳的回答

Cedric
Cedric 2013-5-5
编辑:Cedric 2013-5-5
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 个评论
Amir Pasha Zamani
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
Walter Roberson 2021-4-6
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.

请先登录,再进行评论。

更多回答(1 个)

Micah Ackerman
Micah Ackerman 2016-10-30
编辑:Walter Roberson 2016-10-30
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)

类别

Help CenterFile Exchange 中查找有关 Workspace Variables and MAT-Files 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by