フィルターのクリア

if loop inside matlab function ----- i dont understand why this is not working

1 回表示 (過去 30 日間)
Ramu Nair R
Ramu Nair R 2018 年 4 月 22 日
編集済み: Ramu Nair R 2018 年 9 月 8 日
function y = fcn(u)
if(u>0.7) && (u<0.71)
y=1;
end
It gives error when put inside my simulink simulation:
Output argument 'y' is not assigned on some execution paths.
Function 'MATLAB Function' (#38.9.10), line 1, column 10:
"y"
Launch diagnostic report.
Component:MATLAB Function | Category:Coder error
Errors occurred during parsing of MATLAB function 'MATLAB Function'
  11 件のコメント
Stephan
Stephan 2018 年 4 月 22 日
編集済み: Walter Roberson 2018 年 9 月 8 日
function y = fcn(u)
y=0;
if(u>0.7) && (u<0.71) && y=0
y=1;
end
This could help to latch i guess
Ramu Nair R
Ramu Nair R 2018 年 9 月 8 日
編集済み: Ramu Nair R 2018 年 9 月 8 日
function y = fcn(u)
y=0;
if ((u>0.7) && (u<0.71) && y=0)
y=1;
end
I am getting the following error: Simulink cannot determine sizes and/or types of the outputs for block 'MATLAB Function' 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.

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

回答 (1 件)

Ameer Hamza
Ameer Hamza 2018 年 4 月 22 日
編集済み: Ameer Hamza 2018 年 4 月 23 日

Here is a event based solution to latch the value. The solution use if block and if action subsystem to latch the output once a certain condition is met. I used the clock as the input and the if condition becomes true between 20 to 21 seconds but output remains 1 after 20 seconds.

The Simulink model file is also attached.

  13 件のコメント
Walter Roberson
Walter Roberson 2018 年 9 月 8 日
Making init optional is not feasible for Simulink use. You would need to disable a port by disconnecting it, or you would need to use enabled subsystems that turned off an input (and I do not know how Simulink is defined to behave in that case.)
Once placed and connected, any one Simulink block is expected to always be called with the same number of inputs.
Ramu Nair R
Ramu Nair R 2018 年 9 月 8 日
編集済み: Ramu Nair R 2018 年 9 月 8 日
Thanks a lot, Roberson and all others who contributed to the discussion. Now, it is doing what it is supposed to do !!

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

カテゴリ

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