How to solve a matlab function on simulink? (output cannot be an mxArray in this context)

5 ビュー (過去 30 日間)
Inês Correia
Inês Correia 2019 年 1 月 3 日
コメント済み: Walter Roberson 2020 年 10 月 20 日
I'm using a matlab function on simulink like this:
function [u1,u2] = fcn(To,desf,clock)
t = clock;
F=1/To;
coder.extrinsic('square');
u1=square(2*pi*F*t);
u2=square(2*pi*F*(t-desf));
end
But appears this mistake:
Function output 'u1' cannot be an mxArray in this contextoutput 'u1' cannot be an mxArray in this context. Consider preinitializing the output variable with a known type. Function 'Controlador/Controlo/Modelador/MATLAB Function1' (#248.10.12), line 1, column 11: "u1" Launch diagnostic report.
How do I solve this?

回答 (1 件)

Walter Roberson
Walter Roberson 2019 年 1 月 4 日
u1 = zeros(size(t));
u2 = zeros(size(t));
before doing the current assignments to u1 and u2.
  2 件のコメント
Rafael Cordero
Rafael Cordero 2020 年 10 月 20 日
What if you don't know what the size of u1 and u2 will be? Is there a way around that?
Walter Roberson
Walter Roberson 2020 年 10 月 20 日
I am not sure. You might be able to use coder.varsize

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

カテゴリ

Help Center および File ExchangeSignal Attributes and Indexing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by