simulink function block error: Function output 'y' cannot be an mxArray in this context.

10 vues (au cours des 30 derniers jours)
Jiang Ping
Jiang Ping le 6 Jan 2019
Commenté : Jiang Ping le 9 Jan 2019
i am dealing with a function block in simulink, trying to calculate the interval of a signal with variable frequency to get the real time frequency. My thought is to use tic/toc get the interval between two peaks.
So confused by this error. The diagnostic says:
Function output 'y' cannot be an mxArray in this context. Consider preinitializing the output variable with a known type. Function 'MATLAB Function1' (#312.9.10), line 1, column 10: "y" Launch diagnostic report.
Simulink cannot determine sizes and/or types of the outputs for block 'signalTimer/MATLAB Function1' due to errors in the block body, or limitations of the underlying analysis. The errors might be inaccurate. Fix the indicated errors, or explicitly specify sizes and/or types for all block outputs.
function y = timer(u)
coder.inline('never');
coder.extrinsic('toc')
coder.extrinsic('tic')
persistent x1 x2
% x1=0;
% x2=0;
if isempty(x1)
x1 = 0;
x2 = 0;
else
x2=x1;
end
x1=u;
if x1<x2
y=toc;
y=double(y);
tic
end
end
  2 commentaires
Vishal Chaudhary
Vishal Chaudhary le 9 Jan 2019
"tic' must be called without an output argument before calling "toc".
Jiang Ping
Jiang Ping le 9 Jan 2019
Thank you, but this problem can be addressed if I execute tic in the command line before run the script. Actually what I am really want to do is to measure the frequency of sqaure wave whose frequency is variable in real time .

Connectez-vous pour commenter.

Réponses (0)

Catégories

En savoir plus sur Simulink Functions dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by