simulink add block wrong output
4 views (last 30 days)
Show older comments
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1271420/image.png)
Hello, this is my simulink model
and I cannot understand why my add block output wrong answer
How can I fix it?
0 Comments
Answers (2)
Nikhilesh
on 23 Jan 2023
This looks like an issue of Variable solver. Please have a look at the following discussion
0 Comments
Paul
on 23 Jan 2023
Edited: Paul
on 23 Jan 2023
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)![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1272060/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1272060/image.png)
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
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1272065/image.png)
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 Comments
See Also
Categories
Find more on Simulink Functions in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!