If else condition is not working properly in matlab function block

7 ビュー (過去 30 日間)
Nandhini
Nandhini 2023 年 9 月 28 日
コメント済み: Nandhini 2023 年 9 月 29 日
function [y1,y2]= fcn(u1,u2,u3,u4)
if u1 > 5
y1=u2;
else y1=u3;
end
if u1 < 5
y2=u3;
else y2=u2;
end
I implemented this function in MATLAB function but my output of MATLAB function block always comes as 5 it is not taking the input properely and it is also showing 5 when it is really less than 5 also,here iam giving this output to controlled current source.
  12 件のコメント
Sam Chak
Sam Chak 2023 年 9 月 29 日
I have attached the plots of the u1 and y1 signals (Scope 2 and Scope 3, respectively). The code in the MATLAB Function block works as expected. What is the desired signal for y1? It may be possible to construct the function mathematically.
Blocks under the Masked system (Speed regulator PI controller):
u1 signal:
y1 signal:
Nandhini
Nandhini 2023 年 9 月 29 日
Hi thank you for the comment.I have another doubt,i want to check this loop after the half of simulation time,so that i can avoid intial oscillations.for example i want to avoid the first 0.5s simulation time for this MATLAB function loop,kindly help me how this can be implemented.

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

回答 (1 件)

Amir Azadeh Ranjbar
Amir Azadeh Ranjbar 2023 年 9 月 28 日
If you want me to provide better guidance, please tell me more about your goal for writing this function.
function [y1,y2]= fcn(u1,u2,u3,u4)
if u1>=5
y1 = u2 ;
else
y2 = u3 ;
end
end
  4 件のコメント
Sam Chak
Sam Chak 2023 年 9 月 29 日
@Nandhini, Can you show share the Simulink file? Use the paperclip icon to attach the file.
Nandhini
Nandhini 2023 年 9 月 29 日
Hi sure the file has been attached.

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

カテゴリ

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

製品


リリース

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by