How to Preintialize system objects in Matlab Function Blocks of Simulink

4 ビュー (過去 30 日間)
BCP
BCP 2021 年 8 月 18 日
回答済み: Shadaab Siddiqie 2021 年 9 月 1 日
Hi guys,
I'm stuck with this issue. I have a typical example where I don't know what data type to use for the preintialisation. I'm using a simple matlab function in simulink model which sends handles of "tcpclient" system object to other matlab function. The script of this function is as follows.
function y = fcn
coder.extrinsic('tcpclient');
y = tcpclient("192.168.0.141",1436);
end
As you can imagine, at the time of compilation Simulink would throw me the following error
Function output 'y' cannot be an mxArray in this context. Consider preinitializing the output variable with a known type.
How would one intialize this type of system objects?

回答 (1 件)

Shadaab Siddiqie
Shadaab Siddiqie 2021 年 9 月 1 日
Hi, to solve this issue, reinitialize the output variable when using tcpclient function in the MATLAB function. It can be implemented by reinitializing as follows:
function y = fcn
coder.extrinsic('tcpclient');
y = 1; % reinitializing the output variable with a known type
y = tcpclient("192.168.0.141",1436);
end

カテゴリ

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

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by