simulink add block wrong output
조회 수: 2 (최근 30일)
이전 댓글 표시
Hello, this is my simulink model
and I cannot understand why my add block output wrong answer
How can I fix it?
댓글 수: 0
답변 (2개)
Nikhilesh
2023년 1월 23일
This looks like an issue of Variable solver. Please have a look at the following discussion
댓글 수: 0
Paul
2023년 1월 23일
편집: Paul
2023년 1월 23일
Hi 기범
I think the issue here is mixing together different fixed point data types. Using R2021b
Here's the model, with the data types show on the signal line (Debug -> Information Overlays -> Ports -> Base Data Types)
We see that the inputs to the sum block are all different fixed point data types, which then are added by the sum block to result in some other fixed point type, and the bit pattern of that apparently results in the display of -4.
The fix is to either get the sum block to promote all of the inputs to a common data type that yields the expected result, or change the model so that all of the inputs to the sum block are the same data type that can correctly represent the result. For an example of the former, I added a Data Type Conversion Block to the top line to force a conversion to double. Apparently the sum block the promotes the other three inputs to double using their values before adding and we get the expected answer
Note the output of the sum block is now double. We could also put the DTC block on all four inputs to the sum block, or modify one or more of the four gain block to force their outputs to double via the Ouput data type on the Signal Attributes tab. Or, you can force the Output data type on the Signal Attributes tab of the sum block to double (there are other valid options if you want something other than double); that seems to work as well.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Sources에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!