Usage of cputime or tic toc in a Matlab Function Block
7 views (last 30 days)
Show older comments
Hello everyone,
I want to use Tic and Toc inside a function of a Simulink Matlab Function Block.
I have this code inside the Matlab Function Block:
function y = fcn(u)
starttime = cputime
sampleTime = 0.01;
if u == 0
y = 1;
else u == 1
y = 0;
end
finaltime = cputime - starttime
%y = 2*u;
end
And this I get:
Function 'cputime' is not supported for code generation. Consider adding coder.extrinsic('cputime') at the top of the function to bypass code generation. Function 'MATLAB Function BITS COUNTER' (#29.32.39), line 2, column 13: "cputime" Launch diagnostic report.
Component:MATLAB Function | Category:Coder error
Can someone give some help about how to use cputime inside a function block?
Thanks in advance.
William
0 Comments
Answers (1)
Nisarg Shah
on 19 Dec 2019
Hi William,
Code generation capabilities for Tic/Toc were added in R2019a. Refer to the doc link below for more information:
Note that 'cputime' does not support code generation.
Example code snippet for a Matlab Function Block:
function [y,t] = fcn(u) % 'u' and 'y' are 200x200 matrix of doubles, 't' is s scalar double
y = coder.nullcopy(u);
tic; % START TIMER
for i = 1:numel(u)
y(i) = u(i) + 3;
end
t = toc; % STOP TIMER AND LOG TIME AS OUTPUT
end
Regards,
Nisarg Shah
0 Comments
See Also
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!