If else condition is not working properly in matlab function block
조회 수: 3 (최근 30일)
이전 댓글 표시
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
2023년 9월 29일
Hi @Nandhini
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.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1496442/image.png)
Blocks under the Masked system (Speed regulator PI controller):
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1496445/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1496448/image.png)
u1 signal:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1496451/image.png)
y1 signal:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1496454/image.png)
답변 (1개)
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
참고 항목
카테고리
Help Center 및 File Exchange에서 String에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!