MATLAB: Difference between revisions

From David's Wiki
Created page with " =Usage= ===Anonymous Functions=== [https://www.mathworks.com/help/matlab/matlab_prog/anonymous-functions.html Reference] <syntaxhighlight lang="matlab"> sqr = @(x) x.^2; </s..."
 
No edit summary
Line 6: Line 6:
<syntaxhighlight lang="matlab">
<syntaxhighlight lang="matlab">
sqr = @(x) x.^2;
sqr = @(x) x.^2;
</syntaxhighlight>
=== Timing Code ===
[https://www.mathworks.com/help/matlab/matlab_prog/measure-performance-of-your-program.html Reference]
<code>tic</code> starts a timer. <code>toc</code> returns the time elapsed in seconds since the started timer.
<syntaxhighlight lang="matlab">
timerVal = tic
  % The program section to time.
elapsedTime = toc(timerVal)
</syntaxhighlight>
</syntaxhighlight>

Revision as of 09:53, 29 September 2019


Usage

Anonymous Functions

Reference

sqr = @(x) x.^2;

Timing Code

Reference tic starts a timer. toc returns the time elapsed in seconds since the started timer.

timerVal = tic
   % The program section to time. 
elapsedTime = toc(timerVal)