Is there way to suppress the timer?

12 ビュー (過去 30 日間)
Joe
Joe 2013 年 5 月 5 日
コメント済み: Walter Roberson 2021 年 4 月 6 日
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
Amir Pasha Zamani 2021 年 4 月 6 日
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)
  1 件のコメント
Kai Xin
Kai Xin 2018 年 11 月 12 日
This works without put the toc at the beginning of the code.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeWorkspace 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