Calling a Matlab function from workspace to Simulink matlab function block

19 ビュー (過去 30 日間)
I have 2 functions that I want to use in the Matlab_function block in simulink, however, the functions are too long for copying and writing them in the script of the block (I get this display " Output truncated. Text exceeds maximum line length for Command Window display."). I tried only calling them or using function handle in the block script but it doesn't work. Is there a way I can call this function into my simulink file?

採用された回答

Sayyed Ahmad Fani Yazdi
Sayyed Ahmad Fani Yazdi 2019 年 1 月 14 日
use in simulink function
eml.extrinsic('YourFunctionNameInMatlab');
for example
function [val_out] = fcn(Val_in)
%#eml
eml.extrinsic('YourFunctionNameInMatlab');
Val_out=zeros(1);
[Val] = YourFunctionNameInMatlab(Val_in);
you code use the same rule for a function with more than one input value and more than one output value
  1 件のコメント
Lidia Itzel Morales Gaitán
Lidia Itzel Morales Gaitán 2019 年 1 月 15 日
I tried this and I got this error from Simulink:
"Expected either a logical, char, int, fi, single, or double. Found an mxArray. MxArrays are returned from calls to the MATLAB interpreter and are not supported inside expressions. They may only be used on the right-hand side of assignments and as arguments to extrinsic functions.
Function 'MQ' (#31.136.152), line 8, column 7:
"Q_cir(th1, th1d)"
Launch diagnostic report.
Component:MATLAB Function | Category:Coder error
Errors occurred during parsing of MATLAB function 'MQ'
Component:MATLAB Function | Category:Coder error
Simulink cannot determine sizes and/or types of the outputs for block 'MQ' 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."

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

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by