How can I dynamically define the data type of a persistent variable depending on the type of the input signal in an Embedded MATLAB function block in Simulink 7.6 (R2010b)?

2 ビュー (過去 30 日間)
I am looking for a way to create a persistent variable which dynamically derives its data type from the input Signal in an Embedded MATLAB function block. I know that it is possible to define inputs, parameters and outputs in the Embedded MATLAB function's 'Ports and Data Manager', however I don't know how to automatically set the data type of a variable.

採用された回答

MathWorks Support Team
MathWorks Support Team 2011 年 3 月 4 日
You can use the CLASS function (as shown in the attached emlpersistenttype.mdl) to query the data type of the input signal and use this information when initializing the persistent variable, i.e.:
persistent x
if isempty(x)
x=zeros(10,class(u));
end

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSimulink についてさらに検索

製品


リリース

R2010b

Community Treasure Hunt

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

Start Hunting!

Translated by