How to use integer or other datatype condition in if Block, Simulink?
이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
이전 댓글 표시
Hello,
I want to use condition like if (u ==1), IF block has single/double data type by default, so whenever I generate the code from simulink model, this condition shows u == 1.0F How can I change data type to Int or Boolean so in the autocode it will show u == 1.0 ??
Or any other way to implement if elseif condition where I could change the data type of if condition in Simulink?
Thanks in advance for your answer.
채택된 답변
Fangjun Jiang
2024년 3월 24일
Try this, Use a Relational Operator block where you can specify any data type for the inputs. Specify the output data type as boolean which is the default. Feed this to the IF block where the condition is if (u)
댓글 수: 12
Thanks for the feedback. But I have this condition to implement in if statement (u1 < 0) | (u3 ~= 1)... how is that possible with relational operator as I have total 3 inputs to if block?
Could I use stateflow for this implementation ?
Implement the (u1 < 0) | (u3 ~= 1)... logic using Relational Operator and Logical Operator, then feed the final boolean output to the IF block.
Stateflow could be used but I would say it is an overkill.
There is a problem. For u1 input I have float data type and for u3 I have int8 data type. Now if I use relational operators here, how should I feed to IF block, what should I write in the IF block statement ?
Use Relational Operator blocks to do those individual comparison, then use the Logical Operator to combine them and then feed the final boolean output to the IF block.
I see your point. I can directly put the input coming to IF block from logical operator output. No need any conditions inside the IF block.
Thanks.
one more concern, if I put just u1 here in the If expression, what should it take the value? like if u1 input(coming from that logical operator) is 0 means not executing the IF subsystem block, and u1 input to this IF block is 1, then it will execute first IF action subsystem output?

Yes.
When "flag" is a boolean type, then
if (flag)
is the same as
if (flag==true)
thanks for the feedback.
But actually it's not boolean, I mean when I run it with this implementation, Simulink gives me error saying I need single/double(datatype) input to IF block, so I putted data type conversion block to conver the output of logical block into Single data type and feed it to IF block. Which run successfully. That means it behave the same way as you explain right?
Try it again. I tried. Make the "If expression" as u1. It accepts boolean type. 

However, in the document, it says
"The If block does not support a boolean data type. If you want to input a boolean signal to an If block, convert the signal to an integer type using the Data Type Conversion block."
I see, yes it's runnig now without errors.
Thanks for the help
Update:
I reported the incorrect documentation to the Mathworks tech support. I have been notified that an update/correction of the document will be coming soon.
That's great, thanks for the update.
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Event Functions에 대해 자세히 알아보기
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
