Changing significant digits of constant block

Hi all, I have a basic question. I would like to reduce the number of significant digits in the constant block in Simulink. But I do not know how to do so. Can someone help?
Thanks.

 Akzeptierte Antwort

Andy Bartlett
Andy Bartlett am 24 Okt. 2022
Bearbeitet: Andy Bartlett am 24 Okt. 2022

2 Stimmen

The constant block is showing the text that is entered for the parameter, and is not showing the evaluated numeric value. You do not have control over that behavior of the constant block.
To customize things, you could put a mask on top of the constant block.
Then using the Mask's Initialization code, you could change the value coming from the mask to some quantized value that the mask passes down to the underlying constant block. For example:
desiredInverseValueSpacing = 1000;
valForConstBlock = round(valFromMaskDialog * desiredInverseValueSpacing) / desiredInverseValueSpacing;
% where valForConstBlock is the text entered on the underly constant blocks
% for the 'Constant value:" parameter
Using Mask's MaskDisplay (aka Icon) code, you could use text manipulation techniques to get the specific text you prefer.
For example:
fprintf(num2str(valForConstBlock,6))

Weitere Antworten (1)

Walter Roberson
Walter Roberson am 23 Okt. 2022

1 Stimme

Right click the block, "open", and edit the text version of the constant.

3 Kommentare

Ani R
Ani R am 24 Okt. 2022
Bearbeitet: Ani R am 24 Okt. 2022
But if I connect it to a Knob or some other similar block and vary the constant, it will again show all the digits, won't it?
I believe that Knobs are used to control Parameters, not Constant Block.
Ani R
Ani R am 31 Okt. 2022
I see, thanks.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Simulink finden Sie in Hilfe-Center und File Exchange

Produkte

Version

R2021b

Gefragt:

am 23 Okt. 2022

Kommentiert:

am 31 Okt. 2022

Community Treasure Hunt

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

Start Hunting!

Translated by